I'm trying to learn JavaScript by going through some code in an application and I keep seeing !variable in if conditions. For example: if (!variable.onsubmit || (variable.onsubmit() != false)) { What is it? Some kind of test if the variable is empty? ! is the logical not operator in JavaScript. Formally !expression is read as: Take expression and evaluate it. In your case that
我试图通过浏览应用程序中的一些代码来学习JavaScript,并且在if条件下持续看到!variable 。 例如: if (!variable.onsubmit || (variable.onsubmit() != false)) { 它是什么? 某种测试,如果变量是空的? ! 是JavaScript中的逻辑非操作符。 正式地 !expression被读作: expression并评估它。 在你的情况下,这是variable.onsubmit 计算该评估的结果并将其转换为布尔值。 在你的情况下,因为onsubmit可能是一个
I have four input fields which need to validated at the backend. So i have written one service call and based on output i need to add class to the input field. So if OK then green else red. I want to use same method for all as backend validation is same. So i am trying to return boolean value from the on click function but it always returning false. Here is my code:- <div class="row"&
我有四个需要在后端验证的输入字段。 所以我写了一个服务调用和基于输出我需要添加类到输入字段。 所以如果确定,那么绿色其他红色。 我想要使用相同的方法作为后端验证是一样的。 所以我试图从点击函数返回布尔值,但它总是返回false。 这是我的代码: - <div class="row"><div class="col-md-2 col-md-offset-2 nopadding"><div class="form-group pull-right"><label>Query1:</label
Validation Engine is returning false when no errors were detected and true when validation is unsuccessful, which is the opposite of what I would expect. The weird part is that the tooltips are correct. Take a look at my example. Try the Codepen here. This appears to run counter to the Validation Engine documentation. According to the Validation Engine Docs: validate Validates a form o
验证引擎在未检测到错误时返回false,在验证失败时返回true,这与我所期望的相反。 奇怪的部分是工具提示是正确的。 看看我的例子。 试试这里的Codepen。 这似乎与验证引擎文档相反。 根据验证引擎文档: 验证 验证表单或字段,相应地显示错误提示。 如果表单验证则返回true,如果包含错误则返回false。 对于字段,它在验证时返回true,在错误时返回false。 当使用ajax进行表单验证时,它返回undefined,结果通过
I have a very simple piece of jquery that needs to check a boolean value returned from an ajax call and set a checkbox to checked if it's true. console.log("loc: " + r.location.defaultLocation); if( r.location.defaultLocation == true ) { $('#loc-default').attr('checked',true); } This runs in an onclick function that opens a modal form - if the location info that is returned indicates th
我有一个非常简单的jquery,需要检查从ajax调用返回的布尔值,并设置复选框以检查它是否为真。 console.log("loc: " + r.location.defaultLocation); if( r.location.defaultLocation == true ) { $('#loc-default').attr('checked',true); } 这运行在打开模式窗体的onclick函数中 - 如果返回的位置信息指示这是默认位置,则应检查该复选框。 我们在单个页面上有5个这样的页面 - 即用户可以点击的5个位置。 我碰到的是
i make a Aspx.page On a Single button Click event i want to call both Required Field Validator And My Java Script Function My problem is that Required Field Validator return False and next Java Script Function returns true then page is executed which is wrong i want to restrict first one (if this is false ) how can i do it. <asp:Button ID="btnViewReport" runat="server" c
我做一个Aspx.page在一个单一的按钮单击事件,我想调用必需的字段验证和我的Java脚本功能我的问题是必需的字段验证返回False和下一个Java脚本函数返回true然后页面执行这是错误的我想要限制第一个(如果这是假的)我该怎么做。 <asp:Button ID="btnViewReport" runat="server" class="button" Text="<%$ Resources:Resource, btnViewReport %>" OnClick="btnViewReport_
I am trying to read the source code of Zepto.js . And there is a place in function matches that I don't understand: zepto.matches = function(element, selector) { if (!selector || !element || element.nodeType !== 1) return false var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || element.oMatchesSelector || element.matchesSel
我正在尝试阅读Zepto.js的源代码。 在函数matches中有一个我不了解的地方: zepto.matches = function(element, selector) { if (!selector || !element || element.nodeType !== 1) return false var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || element.oMatchesSelector || element.matchesSelector if (matchesSelector) return matchesSele
I view the code of express, and see this code https://github.com/visionmedia/express/blob/master/lib/application.js#L490 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this); what the ~ means before envs In case you were wondering why it is used in that situation, it is a shorthand for finding out if indexOf method found something. indexOf returns -1 when it doesn't find
我查看express的代码,并查看此代码https://github.com/visionmedia/express/blob/master/lib/application.js#L490 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this); ~在envs之前意味着什么 如果你想知道为什么在这种情况下使用它,它是查找indexOf方法是否找到某种东西的简写。 indexOf在找不到某些内容时返回-1,当它返回时则返回> = 0。 所以当你做〜-1时,你得到0(一个虚假值),当你做任
I've been Googling and searching Stack Overflow for a while, but I just can't get around this problem. I have a standard HTML table, containing, say, fruit. Like so: <table> <tr> <td>Apple</td> <td>Green</td> </tr> <tr> <td>Grapes</td> <td>Green</td> </tr> <tr>
我一直在谷歌搜索和搜索堆栈溢出了一段时间,但我无法解决这个问题。 我有一个标准的HTML表格,包含水果等。 像这样: <table> <tr> <td>Apple</td> <td>Green</td> </tr> <tr> <td>Grapes</td> <td>Green</td> </tr> <tr> <td>Orange</td> <td>Orange</td&g
This question already has an answer here: Javascript formatting for if condition [duplicate] 6 answers Put your values into an array, and check if your item is in the array: if ([1, 2, 3, 4].includes(test.type)) { // Do something } If a browser you support doesn't have the Array#includes method, you can use this polyfill. Short explanation of the ~ tilde shortcut: Update: Since
这个问题在这里已经有了答案: Javascript格式为if条件[复制] 6个答案 把你的值放入数组中,并检查你的项目是否在数组中: if ([1, 2, 3, 4].includes(test.type)) { // Do something } 如果您支持的浏览器没有Array#includes方法,则可以使用此polyfill。 在简要解释~波浪号快捷方式: 更新:由于我们现在有includes方法,还有在使用不点~砍了。 只要将这一点留给那些有兴趣知道它是如何工作和/或在其他代码中遇
This question already has an answer here: How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call? 13 answers It means nothing in jQuery as it is JavaScript. ~ is an operator that does something that you'd normally think wouldn't have any purpose. It is a unary operator that takes the expression to its right performs this sm
这个问题在这里已经有了答案: !!〜(不是不用颚化/砰砰砰砰声)改变'contains / included'数组方法调用的结果吗? 13个答案 这对jQuery没有任何意义,因为它是JavaScript。 ~是一个运算符,它执行你通常认为没有任何目的的事情。 它是一个一元运算符,它的右边表达式对它执行这个小算法(其中N是代字号右边的表达式): - (N + 1)。 见下面的一些样品。 console.log(~-2); // 1 console.log(~-1); // 0 cons