Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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了解select表单中的非选定值_Javascript_Jquery - Fatal编程技术网

Javascript 使用jquery了解select表单中的非选定值

Javascript 使用jquery了解select表单中的非选定值,javascript,jquery,Javascript,Jquery,我想知道选择表单中未选择的元素。(此select是使用for循环动态创建的) 我知道如何知道所选的值 $('#bbdd_btn').click(function(){ $("#select_nodes").each(function() { var selected = $(this).children(":selected").val(); console.log(selected); }); }); 但我想知道未选中的。我读了一些帖子,发现了

我想知道
选择表单
中未选择的元素。(此
select
是使用
for循环
动态创建的)

我知道如何知道所选的值

$('#bbdd_btn').click(function(){
    $("#select_nodes").each(function() {
        var selected = $(this).children(":selected").val();
        console.log(selected);
    });
});
但我想知道未选中的。我读了一些帖子,发现了一些问题,但我不知道如何正确处理。我试试这个

$('#bbdd_btn').click(function(){
    $("#select_nodes").each(function() {
        var selected = $(this).children(":selected").val();
        console.log(selected);

        var not_selected = $(this).children:not(":selected").val();
        //var no_selected = $(this):not(":selected").val();
        //var no_selected = $(this).children(:not(":selected").val();
        console.log(not_selected);
    });
});
哪种方法是正确的


非常感谢。

您可以用这种方式更改代码

$('#bbdd_btn').click(function(){
   $("#select_nodes option").each(function() {
      if($(this).is(':selected')){
        console.log(selected);
      }else{
        console.log(not_selected);
      }      
   });
});

但在这里,选择的和未选择的选项在哪里?在“如果”语句中,您可以筛选选择的和未选择的选项