Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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 jQuery-如果未选择,则忽略选择_Javascript_Jquery - Fatal编程技术网

Javascript jQuery-如果未选择,则忽略选择

Javascript jQuery-如果未选择,则忽略选择,javascript,jquery,Javascript,Jquery,我正在使用下面的代码,正如您所看到的,我选择仅在未选中第7个td元素的select字段时执行操作。即使如此,当在页面加载时选择值时,代码仍在执行 我还必须做些什么来确保它正常工作吗 if (jQuery("div.amfinder-horizontal td:nth-child(7) select").is(':visible') && jQuery('div.amfinder-horizontal td:nth-child(5) select option:selected')

我正在使用下面的代码,正如您所看到的,我选择仅在未选中第7个td元素的select字段时执行操作。即使如此,当在页面加载时选择值时,代码仍在执行

我还必须做些什么来确保它正常工作吗

if (jQuery("div.amfinder-horizontal td:nth-child(7) select").is(':visible') && jQuery('div.amfinder-horizontal td:nth-child(5) select option:selected').length > 0 && jQuery('div.amfinder-horizontal td:nth-child(7) select option:not(:selected)')) {
  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();
}

谢谢

我猜您需要一个事件处理程序,因为现在它只在PageLoad上运行有多少行?您需要在超时处理程序中移动if条件,这可能建议您在jsfiddle.net中创建一个演示。。。太多未知而看不到实时版本如果这是一个ID,则选择器错误:$'finder-4023-20454'应该是$'finder-4023-20454'