如果选择了下拉列表中的某些值,请取消选中复选框

当我从下拉列表中选择某个值或用户没有从下拉列表中选择任何值时,我需要取消选中我的复选框。 我现在正在使用Jquery。 这是我现在使用的代码,但它不起作用。

脚本

  function sdp4(str) { if ( $('#drop1').val()!= '' || $('#drop1').val()== "In Process" || $('#drop1').val()== "KIV" ) {$('#checkbox1').prop('checked', false);} else {$('#checkbox1').prop('checked', true);}  

HTML

     In Process   KIV   Completed    

假设您选中复选框的唯一时间是选中完成时:

  $("#drop1").on('change', function () { var val = $(this).val(); if (val === " " || val === "In Process" || val === "KIV") { $('#checkbox1').prop('checked', false); return; } $('#checkbox1').prop('checked', true); }); 

和HTML:

   

这是一个FIDDLE

你需要实际绑定对sdp4的调用:

 $("#drop1").on('change', sdp4); 

此时,当你可以使用this时,在选择器中使用#drop1也是多余的。

试试这个: http : //jsfiddle.net/7cqDB/

 function sdp4(str) { if (str == '' || str == "In Process" || str == "KIV") { $('#checkbox1').prop('checked', false); } else { $('#checkbox1').prop('checked', true); } } $(function () { $('select').on('change', function () { var str = $(this).val(); sdp4(str); }); });