This question already has an answer here: Change the selected value of a drop-down list with jQuery 15 answers Try $('#owner_select').val(id); http://jsfiddle.net/qWycT/ function select( id ) { var select = $( '#owner_select' ), option = select.find( 'option' ); option.each( function( index ) { if( $( this ).val() == id ) { $( this ).attr( 'selected', '
这个问题在这里已经有了答案: 用jQuery 15个答案更改下拉列表的选定值 尝试 $('#owner_select').val(id); http://jsfiddle.net/qWycT/ function select( id ) { var select = $( '#owner_select' ), option = select.find( 'option' ); option.each( function( index ) { if( $( this ).val() == id ) { $( this ).attr( 'selected', 'selected' ); } }); select
This question already has an answer here: Change the selected value of a drop-down list with jQuery 15 answers This doesn't interpret the variable therein: find('option[value=data.tasks_deliverable_id]') That string value is a literal string. It's specifically looking for a value called "data.tasks_deliverable_id". To use the data variable, you need it to be outside the
这个问题在这里已经有了答案: 用jQuery 15个答案更改下拉列表的选定值 这并不解释其中的变量: find('option[value=data.tasks_deliverable_id]') 该字符串值是一个文字字符串。 它特别寻找一个名为“data.tasks_deliverable_id”的值。 要使用data变量,你需要它在字符串之外: find('option[value=' + data.tasks_deliverable_id + ']') $.get('loadTaskDetails' + $taskId, {taskId: $taskId}, function(data) {
I have a web application. In one of the pages, I go all over the HTML element IDs wether one of them ends with a specified string or not. Every JS functions work on the page but "endsWith" function doesn't work. I really didn't understand the matter. Can anyone help? var str = "To be, or not to be, that is the question."; alert(str.endsWith("question.")); The above simple
我有一个Web应用程序。 在其中一个页面中,我遍历HTML元素ID,其中一个以指定的字符串结束。 每个JS函数都在页面上工作,但“endsWith”函数不起作用。 我真的不明白这件事。 谁能帮忙? var str = "To be, or not to be, that is the question."; alert(str.endsWith("question.")); 上述简单的JS代码根本不起作用? 正如在这篇文章中所说http://rickyrosario.com/blog/javascript-startswith-and-endswith-implementatio
This task requires that you write a function that takes two arguments. The first argument is a string called str and the second argument is a string that our target ending named target . The task is to verify that the ending of str is identical to the target ending. The instructions indicate to use the .substr() method to compare the endings to the targets. The problem I have is that there ar
此任务要求您编写一个带有两个参数的函数。 第一个参数是一个名为str的字符串,第二个参数是我们目标结束命名target的字符串。 任务是验证str的结尾是否与目标结尾相同。 说明指示使用.substr()方法将结尾与目标进行比较。 我.substr的问题是.substr方法会有多个起点和长度参数,因为目标结尾可能是可变长度的。 看看我试图解决这个问题,请指导我走正确的道路。 function end(str, target) { var start = str.length - (
I have a string var s1 = "a,$,b,c"; I want to check if another string ends with s1 So if I send these strings it has to return true w,w,a,$,b,c ^,^,^,$,@,#,%,$,$,a,$,b,c a,w,e,q,r,f,z,x,c,v,z,$,W,a,$,b,c And for these false a,$,b,c,F,W a,$,b,c,W a,$,b,c,$,^,,/ How can I check it? if (str.slice(-s1.length) == s1) { } Or, less dynamically and more literally: if (str.slice(-7) == s1) {
我有一个字符串 var s1 = "a,$,b,c"; 我想检查另一个字符串是否以s1结尾 所以如果我发送这些字符串,它必须返回true w,w,a,$,b,c ^,^,^,$,@,#,%,$,$,a,$,b,c a,w,e,q,r,f,z,x,c,v,z,$,W,a,$,b,c 对于这些false a,$,b,c,F,W a,$,b,c,W a,$,b,c,$,^,,/ 我如何检查它? if (str.slice(-s1.length) == s1) { } 或者,不那么动态和更直接: if (str.slice(-7) == s1) { } 使用slice()的负偏移量将从字符串末尾开始的
I need to get an overlay to slide down based on what the URL has at the end of it. If (URL has 'faq' at the end) { overlay comes down } How can you do that in jQuery/JavaScript? If your URL looks something like this http://yourdomain.com/faq , you could do something like this: var url = window.location.href; var lastPart = url.substr(url.lastIndexOf('/') + 1); if (lastPart === "fa
我需要根据网址结尾处的内容来获取叠加层。 如果(网址在最后有'常见问题'){叠加层下来} 你怎么能在jQuery / JavaScript中做到这一点? 如果您的网址类似于http://yourdomain.com/faq ,则可以这样做: var url = window.location.href; var lastPart = url.substr(url.lastIndexOf('/') + 1); if (lastPart === "faq") { // Show your overlay } 这将有可能检查其他结局并对其采取行动。 更新: 为了
I need to make a Javascript array from URL, eg: turn this: http://maps.google.com/maps/api/staticmap?center=Baker Street 221b, London&size=450x450&markers=Baker Street 221b, London&sensor=false Into something like: array['center'] = Baker Street 221b, London array['size'] = 450x450 // and so on... I need to make this serializaion/unserialization work both ways (url to array and
我需要从URL创建一个Javascript数组,例如: 打开这个: http://maps.google.com/maps/api/staticmap?center=Baker Street 221b, London&size=450x450&markers=Baker Street 221b, London&sensor=false 像这样的东西: array['center'] = Baker Street 221b, London array['size'] = 450x450 // and so on... 我需要使这个serializaion / unserialization工作两种方式(URL到阵列和数组的URL部分)。 有没有
找出字符串是否以特定值结尾的最简单方法是什么? you could use Regexps, like this: str.match(/value$/) which would return true if the string has 'value' at the end of it ($). 从prototypejs窃取: String.prototype.endsWith = function(pattern) { var d = this.length - pattern.length; return d >= 0 && this.lastIndexOf(pattern) === d; }; 'slaughter'.endsWith('laughter'); //
找出字符串是否以特定值结尾的最简单方法是什么? 你可以使用Regexps,就像这样: str.match(/value$/) 如果字符串在它的末尾有'value'($),它将返回true。 从prototypejs窃取: String.prototype.endsWith = function(pattern) { var d = this.length - pattern.length; return d >= 0 && this.lastIndexOf(pattern) === d; }; 'slaughter'.endsWith('laughter'); // -> true 常用表达"Hell
This question already has an answer here: endsWith in JavaScript 29 answers 就像是var check = "project", url = "/home/doc/some-user-project/project"; if (url.substr(-check.length) == check){ // it ends with it.. } Try this <script> var url = "/home/doc/some-user-project/project"; url.match(/project$/); </script> The response is a array with project, if the responde is
这个问题在这里已经有了答案: endsWith在JavaScript 29答案 就像是var check = "project", url = "/home/doc/some-user-project/project"; if (url.substr(-check.length) == check){ // it ends with it.. } 尝试这个 <script> var url = "/home/doc/some-user-project/project"; url.match(/project$/); </script> 响应是一个包含项目的数组,如果responde由于未找到而为'null'
This question already has an answer here: endsWith in JavaScript 29 answers You'll want to use the Javascript string method .substr() combined with the .length property. function isDepreciated(var id) { var id = "string value - depreciated"; var lastdepreciated = id.substr(id.length - 13); // => "- depreciated" //return true or false check for true or flase } This gets th
这个问题在这里已经有了答案: endsWith在JavaScript 29答案 您将要使用与.length属性组合的Javascript字符串方法.substr() 。 function isDepreciated(var id) { var id = "string value - depreciated"; var lastdepreciated = id.substr(id.length - 13); // => "- depreciated" //return true or false check for true or flase } 这将获得从id.length - 13开始的字符,并且由于省略了.substr()的