Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试确定select是否选择了值时出现语法错误_Javascript_Jquery - Fatal编程技术网

Javascript 尝试确定select是否选择了值时出现语法错误

Javascript 尝试确定select是否选择了值时出现语法错误,javascript,jquery,Javascript,Jquery,我正在尝试使用以下代码确定SELECT元素是否具有所选的值 if (jQuery("div.amfinder-horizontal td:nth-child(7) select").is(':visible') && (jQuery('jQuery("div.amfinder-horizontal td:nth-child(5) select > [selected]').length > 0)) { // The following two l

我正在尝试使用以下代码确定SELECT元素是否具有所选的值

if (jQuery("div.amfinder-horizontal td:nth-child(7) select").is(':visible') && (jQuery('jQuery("div.amfinder-horizontal td:nth-child(5) select > [selected]').length > 0))      {
      // The following two lines are commands for a Prototype script, in place to simulate the change event
      setTimeout(function() {
          jQuery("div.amfinder-horizontal td:nth-child(6) select option").each(function() { this.selected = (this.text == "<?php echo Mage::registry('current_category')->getName(); ?>"); });
          jQuery("div.amfinder-horizontal td:nth-child(6) select option").change();
          $('finder-4023--20454').simulate('click'); // This is the ID of the select element ( it is the same as div.amfinder-horizontal td:nth-child(6) select )
          $('finder-4023--20454').simulate('change'); // This is the ID of the select element ( it is the same as div.amfinder-horizontal td:nth-child(6) select )
          console.log('Changed!');
      }, 700);
      jQuery("#popover6").show();
  }
我遇到的问题是这个错误-未捕获错误:语法错误,无法识别的表达式:jQuerydiv.amfinder-horizontal td:nth-child5 select>[selected]

您可以帮助解决这个语法错误吗

谢谢

我建议您使用select option:selected而不是错误的select>[selected]选择器

代码的第二部分有点混乱,请尝试以下操作:

&& (jQuery('div.amfinder-horizontal td:nth-child(5) select > option:selected').length > 0)
应该是

[:selected]
嗯。。。不知道你想在那里做什么

也许是这个

jQuery('div.amfinder-horizontal td:nth-child(5) select > :selected')

我猜OP想要:selected,但如果在DOM中指定,[selected]选择器仍然可以检索select的默认值。这就是错误的语法:jQuery'jQuery。。。从选择器中删除第二个jQuery
jQuery('div.amfinder-horizontal td:nth-child(5) select > :selected')