清除select選中狀態


要做這樣一種功能,當我點擊左邊的下拉框的時候,右邊下拉框啟用進行選擇。如下圖:

當左邊重新點擊“請選擇”的時候,右邊選擇狀態清空並禁用:

這個很好做,用到只需要獲取所選擇Index就行(默認從0開始) 下面是js代碼:

function changeMorTime(obj)
{

    //當左邊select控件所選擇為請選擇時
    if (obj.selectedIndex == 0)

   {

    //獲取 右邊用葯計量控件
     var cselc = document.getElementById("MorTime");
     cselc.options.selectedIndex = 0; //回到初始狀態
    $("#MorTime").attr("disabled", "disabled");//禁用
   }
   else

  {
    $("#MorTime").removeAttr("disabled");
  }
}

 html代碼如下:

<td>
  <select class=" check-input" onload="IninSageALLTime()" onchange="changeMorTime(this)" id="dosageMorTime" name="dosageMorTime" required="required">
  </select>
</td>

<td >
  <select class=" check-input" " name="dosagesize" id="MorTime" required="required">
  </select>&nbsp; 片
</td>

以上寫的有點混亂既有js也有jquery,有需要的可以自己更改一下。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM