easydropdown取决于选择

时间:2016-07-26 19:50:41

标签: jquery drop-down-menu jquery-selectbox

我使用easydropdown(https://github.com/patrickkunka/easydropdown)来设置我的选择下拉字段的样式。

到目前为止,非常好。

然而,当尝试使2个选择框可靠时,第二个框保留初始值。 我试过jsfiddle,jet似乎无法正确添加资源: 例如:

http://jsfiddle.net/49FK9/46/

<script type='text/javascript' src="https://cdn.jsdelivr.net/jquery.easydropdown/2.1.4/jquery.easydropdown.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.easydropdown/2.1.4/themes/easydropdown.css">
<select name="test1" class="dropdown" id="test1">
      <option value="0">Select</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
    </select>
    <select name="test2" class="dropdown" id="test2">
      <option value="0">Select</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
    </select>

    <script type='text/javascript'>document.getElementById('test1').addEventListener("change", function() {
  document.getElementById('test2').selectedIndex = document.getElementById('test1').selectedIndex;
}, false);</script>

我很感激任何帮助。

2 个答案:

答案 0 :(得分:0)

<script type='text/javascript' src="https://cdn.jsdelivr.net/jquery.easydropdown/2.1.4/jquery.easydropdown.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.easydropdown/2.1.4/themes/easydropdown.css">
<select name="test1" class="dropdown" id="test1">
      <option value="0">Select</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
    </select>
    <select name="test2" class="dropdown" id="test2">
      <option value="0">Select</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
    </select>
<script type='text/javascript'>
    document.getElementById('test1').addEventListener("change", function() {
  document.getElementById('test2').selectedIndex = document.getElementById('test1').selectedIndex;
}, false);
</script>

答案 1 :(得分:0)

设法让它工作,但使用bootstrap-select而不是easydropdown。

$(&#39; .selectpicker&#39;)selectpicker。(&#39;刷新&#39);做了这份工作