jQuery給表單設定值

來源:互聯網
上載者:User

標籤:下拉框   style   cte   單選   utf-8   jquery   log   lte   click   

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script src="js/jquery-1.11.3.min.js"></script>    <script>        $(function () {            $("input[type=button]:eq(0)").click(function () {                $("#single").val("選擇2號");            });            $("input[type=button]:eq(1)").click(function () {                $("#multiple").val(["選擇2號","選擇3號"]);            })            $("input[type=button]:eq(2)").click(function () {                $(":checkbox").val(["check2","check3"]);//等同於$("input[type=checkbox]").filter(":eq(0),:eq(1)").attr("checked","checked")                $(":radio").val(["radio3"]);//等同於$("input[type=radio]").attr("checked","checked"),雖然是單選框,取值還是得用數組            });        });    </script></head><body><input type="button" value="設定單選下拉框選中"/><input type="button" value="設定多選下拉框選中"/><input type="button" value="設定單選框和多選框選中"/><br/><br/><select id="single">    <option>選擇1號</option>    <option>選擇2號</option>    <option>選擇3號</option></select><select id="multiple" multiple="multiple" style="height:120px;">    <option selected="selected">選擇1號</option>    <option>選擇2號</option>    <option>選擇3號</option>    <option>選擇4號</option>    <option selected="selected">選擇5號</option></select><br/><br/><input type="checkbox" value="check1"/> 多選1<input type="checkbox" value="check2"/> 多選2<input type="checkbox" value="check3"/> 多選3<input type="checkbox" value="check4"/> 多選4<br/><input type="radio" value="radio1"/> 單選1<input type="radio" value="radio2"/> 單選2<input type="radio" value="radio3"/> 單選3</body></html>

 

jQuery給表單設定值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.