亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用jQuery動態(tài)設(shè)置單選框的選中效果

 更新時間:2018年12月06日 09:17:02   作者:賀劉芳  
這篇文章主要介紹了使用jQuery動態(tài)設(shè)置單選框的選中效果,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

一、需要實(shí)現(xiàn)的效果

這里使用jQuery來實(shí)現(xiàn)。需要實(shí)現(xiàn)的效果如下:當(dāng)下拉條改變時,單選框選中的值隨之變化。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>動態(tài)設(shè)置單選框的選中</title>
    <!--
      作者:Harrison
      時間:2018-12-05
      描述:當(dāng)下拉條改變時,動態(tài)的設(shè)置單選框的值
    -->
  </head>
  <body>
    <select id="sexSelect" style="width: 10%;">
      <option value="1">男</option>
      <option value="2">女</option>
    </select>
    男:<input type="radio" value="1" name="sex" id="sexRadio1" checked/>
    女:<input type="radio" value="2" name="sex" id="sexRadio2"/>
  </body>
  <script type="text/javascript" src="js/jquery-1.7.2.min.js" ></script>
  <script type="text/javascript">
    $("#sexSelect").change(function(){
      //獲取選中的下拉條
      var checkedOfSelect = $("#sexSelect").val();
      //動態(tài)設(shè)置單選框的選中
      if(checkedOfSelect == 1){
        $("#sexRadio1").prop("checked",true);
        $("#sexRadio2").prop("checked",false);
      }
      if(checkedOfSelect == 2){
        $("#sexRadio1").prop("checked",false);
        $("#sexRadio2").prop("checked",true);
      }
    });
  </script>
</html>

二、注意

•當(dāng)設(shè)置單選框的checked屬性時,要使用jQuery的prop()方法,不能夠使用jQuery的attr()方法,attr()只適合簡單html元素設(shè)置。
•jQuery的prop()方法,第二個參數(shù)為布爾值,不能設(shè)置成string類型:

  正確:$("#sexRadio1").prop("checked",true);
  錯誤:$("#sexRadio1").prop("checked","true");

總結(jié)

以上所述是小編給大家介紹的使用jQuery動態(tài)設(shè)置單選框的選中效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論