Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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_Html - Fatal编程技术网

Javascript 添加多个返回jquery

Javascript 添加多个返回jquery,javascript,jquery,html,Javascript,Jquery,Html,如何更改下面的代码,以便可以返回多个id为的元素(操作将发生在多个元素上,而不仅仅是id为=“firstId”的元素)。提前谢谢 $("#main").change(function() { var first = $(this); $('#occupation').prop("disabled", function() { return first.children(":selected").attr("id") === ("firstId");

如何更改下面的代码,以便可以返回多个id为的元素(操作将发生在多个元素上,而不仅仅是id为=“firstId”的元素)。提前谢谢

   $("#main").change(function() {
    var first = $(this);
    $('#occupation').prop("disabled", function() {
        return first.children(":selected").attr("id") === ("firstId");
    });
});

我想这就是你所期待的

$("#employedSelect").change(function() {
    var value = $(this).val();
    var isPresent = false;
    $('#occupation').children("option").each(function(){
       if($(this).val() === value)
           isPresent = true;
    });
    if(isPresent )
      $('#occupation').attr("disabled","disabled");
    else
     $('#occupation').removeAttr("disabled");
});

小提琴:我想这就是你所期待的

$("#employedSelect").change(function() {
    var value = $(this).val();
    var isPresent = false;
    $('#occupation').children("option").each(function(){
       if($(this).val() === value)
           isPresent = true;
    });
    if(isPresent )
      $('#occupation').attr("disabled","disabled");
    else
     $('#occupation').removeAttr("disabled");
});

fiddle:

我读了几遍这篇文章,但我仍然不明白你想做什么。你能在这里提供更多的代码和解释吗?我假设你想发回不止一件东西?您应该使用JSON对象并检查返回的值,以设置您希望执行的任何操作。如果选择了除all或employed之外的任何内容,我希望禁用第二个选择。我读了几遍,但我仍然不清楚您想做什么。你能在这里提供更多的代码和解释吗?我假设你想发回不止一件东西?您应该使用JSON对象并检查返回的值,以设置您希望执行的任何操作。如果选择了除all或employed之外的任何内容,我希望禁用第二个选择。
inArray
将返回索引,如果未找到,则返回
-1
。我想您可以添加
!==-1
。好奇:~-1===0因此:
返回~jQuery.inArray(first.children(“:selected”).attr(“id”),id)
@jacktheripper它确实有效,我在您测试它之后刚刚修改了答案
inArray
将返回索引,如果找不到则返回
-1
。我想您可以添加
!==-1
。好奇:~-1===0因此:
返回~jQuery.inArray(first.children(“:selected”).attr(“id”),id)@jacktheripper它确实有效,我在你测试答案后修改了答案,我根据你的问题问了什么而不是你想做什么。这是一个符合你需要的东西,我是根据你的问题而不是你想做的来回答的。这是适合你需要的东西
$("#employedSelect").change(function() {
    var value = $(this).val();
    var isPresent = false;
    $('#occupation').children("option").each(function(){
       if($(this).val() === value)
           isPresent = true;
    });
    if(isPresent )
      $('#occupation').attr("disabled","disabled");
    else
     $('#occupation').removeAttr("disabled");
});