jQuery表单设置值的方法

时间:2021-05-26

本文实例为大家分享了jQuery如何表单设置值的具体代码,供大家参考,具体内容如下

<!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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章