为什么会出现错误" error:语法错误,无法识别的表达式:unsupported pseudo: select " ?

时间:2022-11-07 18:48:37

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">&times;</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表添加一个新的。但是这一行只包含select控件。因此,我使用上面的代码为那个select控件设置id和名称的值。在此期间,我在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值以选择控件而编写的上述两行代码,那么其他代码就完全没有问题。那么,谁能修复这个问题,并允许我设置新创建的row的select控件的id和值?谢谢

2 个解决方案

#1


10  

There is no selector called :select, just select(element selector) will do - you might have tried it because of the pseudo selector :input which is a special selector that will select all input, select and textarea elements

没有选择器调用:select, just select(元素选择器)将会这样做——您可能尝试过它,因为pseudo选择器:input是一个特殊的选择器,它将选择所有的输入、选择和textarea元素

$('select', new_row)

#2


-1  

":" character only work in pseudo selectors like

"字符只能在伪选择器中工作

 $('tr:nth-child)

#1


10  

There is no selector called :select, just select(element selector) will do - you might have tried it because of the pseudo selector :input which is a special selector that will select all input, select and textarea elements

没有选择器调用:select, just select(元素选择器)将会这样做——您可能尝试过它,因为pseudo选择器:input是一个特殊的选择器,它将选择所有的输入、选择和textarea元素

$('select', new_row)

#2


-1  

":" character only work in pseudo selectors like

"字符只能在伪选择器中工作

 $('tr:nth-child)