Javascript 复选框和下拉菜单之间的事件绑定

Javascript 复选框和下拉菜单之间的事件绑定,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,这是我的桌子: <table> <tr> <td> <label for="check"> <input type="checkbox" name="check" id="check" value="true" /> Select something </label> </td> <

这是我的桌子:

<table>                    
  <tr>
    <td>
      <label for="check">
        <input type="checkbox" name="check" id="check" value="true" />
        Select something
      </label>
    </td>

    <td>
      <label for="select">
        <select name="select" id="select">
        <option value="Default"></option>
        <option value="A">A</option>
        <option value="B">B</option>
      </label>
    <td>
  </tr>

挑选
A.
B

我正在尝试将复选框功能与下拉菜单链接,如下所示:如果复选框未选中,并且用户选择了选项值不是“默认”的选项,则复选框应自动选中,并使用“选定”类突出显示。然后,无论何时选择“默认”值,复选框都应取消选中并取消高亮显示,无论其以前的状态如何。

首先选择函数:

jQuery("#check").on("click", function() {
    if(!jQuery(this).is(":checked")) {
        jQuery("#select").val("Default");
    }
});

jQuery("#select").on("change", function() {
    if(jQuery(this).val() === "Default") {
        jQuery("#check").attr("checked", false);
    }
});
function selectValueChanged(){
  var selected = document.getElementById("select").selectedIndex;
  var options = document.getElementById("select").options;
  if(document.getElementById("check").checked){
    if(options[i].value == "Default"{
      document.getElementById("check").checked = false;
      document.getElementById("check").className = document.getElementById("check").className.replace(" selected", "");
    }
  else{
    if(options[i].value != "Default"){
      document.getElementById("check").checked = true;
      document.getElementById("check").className += " selected";
    }
  }
}
然后给select一个onchage事件,使其看起来像:

<select name="select" id="select" onchange="selectValueChanged()">

尝试使用“onChenge”,如下所示:

<html>
<body>
<table>                    
  <tr>
    <td>
      <label for="check">
        <input type="checkbox" name="check" id="check" value="true" />
        Select something
      </label>
    </td>

    <td>
      <label for="select">
        <select name="select" id="select" onchange="Select_Change(this)">
        <option value="Default"></option>
        <option value="A">A</option>
        <option value="B">B</option>
      </label>
    <td>
  </tr>

<script>
    function Select_Change( elem ) 
    { 
        if (elem.value != 'Default')
        {
            CheckBox_Select( true );
        }
        else
        {
            CheckBox_Select( false ); 
        }
    }

    function CheckBox_Select( check ) 
    { 
        document.getElementById('check').checked = check; 
    }
</script>
</body>
</html>

挑选
A.
B
功能选择更改(elem)
{ 
如果(元素值!=“默认值”)
{
选中复选框(true);
}
其他的
{
选中复选框(false);
}
}
功能复选框\选择(选中)
{ 
document.getElementById('check')。checked=check;
}

你的JS代码在哪里?