This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers 你可以使用.indexOf() : if(str.indexOf(substr) > -1) { }
这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 你可以使用.indexOf() : if(str.indexOf(substr) > -1) { }
Possible Duplicates: Check if text is in a string JavaScript: string contains I'm trying to check if a string I import into my application has a certain piece of text. I know how to do this with jQuery, but how do I do it with straight up JavaScript? Here you go: var test = 'Hello World'; if( test.indexOf('World') >= 0){ // Found world } More information on it can be found her
可能重复: 检查文本是否在字符串中 JavaScript:字符串包含 我试图检查一个字符串,我导入到我的应用程序有一段文字。 我知道如何用jQuery来做到这一点,但我该如何直接使用JavaScript呢? 干得好: var test = 'Hello World'; if( test.indexOf('World') >= 0){ // Found world } 有关它的更多信息可以在这里找到: http://www.w3schools.com/jsref/jsref_IndexOf.asp 检查了这一点,在Stackoverflow上的
This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers Like this: if (str.indexOf("Yes") >= 0) ...or you can use the tilde operator: if (~str.indexOf("Yes")) This works because indexOf() returns -1 if the string wasn't found at all. Note that this is case-sensitive. If you want a case-insensitive search, you can w
这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 喜欢这个: if (str.indexOf("Yes") >= 0) ...或者你可以使用波形符号运算符: if (~str.indexOf("Yes")) 这是indexOf()因为如果根本没有找到字符串, indexOf()返回-1 。 请注意,这是区分大小写的。 如果你想要一个不区分大小写的搜索,你可以写 if (str.toLowerCase().indexOf("yes") >= 0) 要么, if (/yes
I was wondering what the = +_ operator means in JavaScript. It looks like it does assignments. Example: hexbin.radius = function(_) { if (!arguments.length) return r; r = +_; dx = r * 2 * Math.sin(Math.PI / 3); dy = r * 1.5; return hexbin; }; r = +_; + tries to cast whatever _ is to a number. _ is only a variable name (not an operator), it could be "a", &quo
我想知道= + _运算符在JavaScript中意味着什么。 它看起来像是做任务。 例: hexbin.radius = function(_) { if (!arguments.length) return r; r = +_; dx = r * 2 * Math.sin(Math.PI / 3); dy = r * 1.5; return hexbin; }; r = +_; +尝试将任何_转换为数字。 _只是一个变量名(不是操作符),它可能是“a”,“foo”等。 例: +"1" 将“1”投射到纯数字1。 var _ = "1"; var r = +_; r现在是1
Is there a null coalescing operator in Javascript? For example, in C#, I can do this: String someString = null; var whatIWant = someString ?? "Cookies!"; The best approximation I can figure out for Javascript is using the conditional operator: var someString = null; var whatIWant = someString ? someString : 'Cookies!'; Which is sorta icky IMHO. Can I do better? The JavaScript equivalent
Javascript中有一个空合并运算符吗? 例如,在C#中,我可以这样做: String someString = null; var whatIWant = someString ?? "Cookies!"; 我可以找出Javascript的最佳近似值是使用条件运算符: var someString = null; var whatIWant = someString ? someString : 'Cookies!'; 这是不舒服的恕我直言。 我可以做得更好吗? C#空合并运算符( ?? )的JavaScript等价物使用逻辑OR( || ): var whatIWant = someStri
I'm using $.post() to call a server using Ajax and then using the JTemplate to write data to the current page. However, if the session times out, the server sends a redirect directive to send the user to the login page. In this case, jQuery is replacing the div element with the contents of the login page, forcing the user's eyes to witness a rare scene indeed. How can I manage a redir
我使用$.post()使用Ajax调用服务器,然后使用JTemplate将数据写入当前页面。 但是,如果会话超时,服务器将发送重定向指令以将用户发送到登录页面。 在这种情况下, jQuery正在用登录页面的内容替换div元素,强制用户的眼睛确实见证一个罕见的场景。 如何使用jQuery 1.9从Ajax调用管理重定向指令? 您必须使用json数据来响应客户端。 例如:在PHP文件中 <?php //for example, data you want to response to client is
使用jQuery,我如何取消/中止我还没有收到响应的Ajax请求 ? Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort() . See the documentation: abort Method (MSDN). Cancels the current HTTP request. abort() (MDN). If the request has been sent already, this method will abort the request. var xhr = $.ajax({ type: "POST", url: "some
使用jQuery,我如何取消/中止我还没有收到响应的Ajax请求 ? 大多数jQuery Ajax方法返回一个XMLHttpRequest(或等效的)对象,所以你可以使用abort() 。 请参阅文档: 中止方法(MSDN)。 取消当前的HTTP请求。 abort()(MDN)。 如果请求已经发送,则此方法将中止请求。 var xhr = $.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){
This question already has an answer here: How do I redirect to another webpage? 67 answers 使用location.href window.location.href = email; window.location.href = email; 应该将用户重定向到email包含的URL 你可以设置window.location.href: function enter() { var keepGoing = true; var email; while(keepGoing){ keepGoing = false email = prompt("Please Enter Website Addre
这个问题在这里已经有了答案: 我如何重定向到另一个网页? 67个答案 使用location.href window.location.href = email; window.location.href = email; 应该将用户重定向到email包含的URL 你可以设置window.location.href: function enter() { var keepGoing = true; var email; while(keepGoing){ keepGoing = false email = prompt("Please Enter Website Address"); // Website A
This question already has an answer here: How do I redirect to another webpage? 67 answers 尝试这个: function deletePost() { var ask = window.confirm("Are you sure you want to delete this post?"); if (ask) { window.alert("This post was successfully deleted."); window.location.href = "window-location.html"; } }
这个问题在这里已经有了答案: 我如何重定向到另一个网页? 67个答案 尝试这个: function deletePost() { var ask = window.confirm("Are you sure you want to delete this post?"); if (ask) { window.alert("This post was successfully deleted."); window.location.href = "window-location.html"; } }
This question already has an answer here: How do I redirect to another webpage? 67 answers You can use the window.location to redirect a browser: https://developer.mozilla.org/en/DOM/window.location 你可以使用JavaScript的本地 window.location $('#link').click(function(){ if(validation_fails) { window.location="http://this.site.com/"; } else { return true;
这个问题在这里已经有了答案: 我如何重定向到另一个网页? 67个答案 您可以使用window.location重定向浏览器: https://developer.mozilla.org/en/DOM/window.location 你可以使用JavaScript的本地 window.location $('#link').click(function(){ if(validation_fails) { window.location="http://this.site.com/"; } else { return true; } } 您可以将div ID散列到window.locatio