javascript 为什么我收到错误“错误:语法错误,无法识别的表达式:不支持的伪:选择”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23468252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why I'm getting the error "Error: Syntax error, unrecognized expression: unsupported pseudo: select"?
提问by Arun P Johny
I've following jQuery code:
我正在关注 jQuery 代码:
$(document).ready(function() {
$('.products').click(function () {
var table_id = $(this).closest('table').attr('id');
var no = table_id.match(/\d+/)[0];
var first_row = $(this).closest('table').find('tbody tr:first').attr('id');
var new_row = $('#'+first_row).clone();
var tbody = $('tbody', '#'+table_id);
var n = $('tr', tbody).length + 1;
new_row.attr('id', 'reb' + no +'_'+ n);
$(':input', new_row).not('.prod_list').remove();
$(':select', new_row).attr('name','product_id_'+no+'['+n+']');
$(':select', new_row).attr('id','product_id_'+no+'_'+n);
$('<button style="color:#C00; opacity: 2;" type="button" class="close delete" data-dismiss="alert" aria-hidden="true">×</button>').appendTo( $(new_row.find('td:first')) );
tbody.append(new_row);
$('.delete').on('click', deleteRow);
});
});
Using above code I'm appending a new to the HTML table. But this row is containing only select control. So I'm setting the values of id and name to that select control using above code. During this I got Syntax error as follows in firebug console:
使用上面的代码,我将一个新的附加到 HTML 表中。但是这一行只包含选择控件。所以我使用上面的代码将 id 和 name 的值设置为该选择控件。在此期间,我在 firebug 控制台中收到如下语法错误:
"Error: Syntax error, unrecognized expression: unsupported pseudo: select"
If I remove the above two lines I wrote to set the id and name values to select control, other code works absolutely fine without any issue. So can some one please fix this issue and allow me to set the id and value of newly created row's select control? Thanks
如果我删除上面两行我写的设置 id 和 name 值来选择控件,其他代码工作得很好,没有任何问题。那么有人可以解决这个问题并允许我设置新创建的行选择控件的 id 和值吗?谢谢
回答by Arun P Johny
There is no selector called :select
, just select
(element selector) will do - you might have tried it because of the pseudo selector :inputwhich is a special selector that will select all input, select and textarea elements
没有被调用的选择器:select
,只有select
(元素选择器)会做——你可能已经尝试过它,因为伪选择器 :input这是一个特殊的选择器,它将选择所有输入、选择和文本区域元素
$('select', new_row)
回答by Hossein Salmanian
":" character only work in pseudo selectors like
":" 字符只适用于伪选择器,如
$('tr:nth-child)