jquery 【radio checkbox】選擇

來源:互聯網
上載者:User

標籤:jquery radio checkbo

<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script src="Jquery/jquery-1.10.2.js" type="text/javascript"></script>    <script type="text/javascript">        $(function () {            $("#btn1").click(function () {                alert($("input[name='r1']:checked").val())  //擷取選中的值            })            $("#btn2").click(function () {                $("input[name='r1']").val(["男"]); //將“女”設為選中的值 :注意"女"是用中括弧[]括起來的,因為它只是$("input[name='r1']")擷取到的資料是一個數組。            })            //或者寫成這樣也行            //$("input[value='女']").attr("checked", true);        })        //-----------------------------------------------------------------------------------        $(function () {            $("#btn3").click(function () {                 $("input").val(["籃球","乒乓球","女"]) //將input標籤中的 val()值為"籃球","乒乓球","女"的表單選中            })        })        //-------------------------------------------------------------------------------------------        $(function () {            $("#btn4").click(function () {                //$("input[name='c1']").val(["籃球", "乒乓球", "女"]) //將input標籤中name屬性值為c1的,val()值為"籃球",和"乒乓球"的的表單選中                $("input[name='r1'][value='男']").attr("checked", true);            })        })    </script></head><body><input type="radio" name="r1" value="男"/>男<input type="radio" name="r1" value="女"/>女<input type="radio" name="r1" value="保密"/>保密<br/><input type="button" value="擷取選中的值"id="btn1"/><input type="button" value="設定選中的值"id="btn2"/><br/><input type="checkbox" name="c1" value="足球" />足球<input type="checkbox" name="c1" value="籃球" />籃球<input type="checkbox" name="c1" value="羽毛球" />羽毛球<input type="checkbox" name="c1" value="乒乓球" />乒乓球<br/><input type="button" value="設定input表單選中值"id="btn3"/><input type="button" value="設定複選框選中值"id="btn4"/></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.