Home > Article > Web Front-end > Detailed explanation of jQuery form setting value
This article mainly introduces the method of setting values in the jQuery form in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
The example in this article shares the specific code of how to set the value in the jQuery form for your reference. The specific content is as follows
<!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>
Related recommendations:
HTML Set different action_html/css_WEB-ITnose for the same form
ajax to automatically complete form fields example
jQuery form filling example sharing
The above is the detailed content of Detailed explanation of jQuery form setting value. For more information, please follow other related articles on the PHP Chinese website!