duandazhen7306 2013-10-20 22:57
浏览 56
已采纳

从一个选择标记中选择一个值后禁用选择值[关闭]

i have two select option for time selecting if i would select one value say 9:00am from one select tag 9:00am should be disabled from other select tag code is

<select>
<option value="9:00am">9:00am</option>
<option value="10:00am">10:00am</option> </select> so on.



<select>
<option value="9:00am">9:00am</option>
<option value="10:00am">10:00am</option> </select> so on..

These are the two select tag ..

Thanks in Advance,

Ameeth

  • 写回答

3条回答 默认 最新

  • duanjiao6711 2013-10-20 23:14
    关注

    i think this may be what you're looking for

    http://codepen.io/anon/pen/xegKj

    html:

    <select id="TimeFirst" onChange="fSetTimeOptions(this,'TimeSecond');">
      <option value="9:00am">9:00am</option>
      <option value="10:00am">10:00am</option>
    </select>
    <select id="TimeSecond" onChange="fSetTimeOptions(this,'TimeFirst');">
      <option value="9:00am">9:00am</option>
      <option value="10:00am">10:00am</option>
    </select>
    

    js:

    function fSetTimeOptions(selObj, fvOtherSel) {
      var OtherSel = document.getElementById(fvOtherSel);
      var TimeValue = selObj.options[selObj.selectedIndex].value;
      alert(TimeValue);
      for (var i = 0; i < OtherSel.options.length; i++) {
             if (OtherSel.options[i].value == TimeValue) {
                 OtherSel.options[i].disabled = true;
             } else {
                 OtherSel.options[i].disabled = false; 
             }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部