简体   繁体   English

为什么我收到错误“错误:语法错误,无法识别的表达式:不支持的伪:选择”?

[英]Why I'm getting the error “Error: Syntax error, unrecognized expression: unsupported pseudo: select”?

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.使用上面的代码,我将一个新的附加到 HTML 表中。 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.所以我使用上面的代码将 id 和 name 的值设置为该选择控件。 During this I got Syntax error as follows in firebug console:在此期间,我在 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.如果我删除上面写的两行来设置 id 和 name 值来选择控件,其他代码绝对可以正常工作,没有任何问题。 So can some one please fix this issue and allow me to set the id and value of newly created row's select control?那么有人可以解决这个问题并允许我设置新创建的行选择控件的 id 和值吗? Thanks谢谢

没有称为:select器,只需要select元素选择器)就可以了 - 您可能已经尝试过它,因为伪选择器 :input是一个特殊的选择器,可以选择所有输入、选择和 textarea 元素

$('select', new_row)

":" 字符只适用于伪选择器,如

 $('tr:nth-child')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM