javascript代码: $("#setValue").click(function () { //$("input[name=gender]").val(["女"]); $(":radio[name=gender]").val(["女"]);//[]在设值时不能少,单选下拉菜单除外,其它的多选下拉菜单和多选文本框,单选按钮等都要使用[] $("input[type=checkbox]").val(["歌曲一", "歌曲三"]);//一次可以设置多个 $(":checkbox[value=歌曲五]").attr("checked", true);//一次仅设置一个 //$("p").attr({ "title": "张三", "name": "李四" });//以字典形式对各属性进行设定 }); $("#getValue").click(function () { alert($("input[name=gender]:checked").val()); }); $("#allit").click(function () { $(":checkbox").attr("checked", true); }); $("#littleit").click(function () { $(":checkbox").attr("checked", false); }); $("#revelit").click(function () { $("input[type=checkbox]").each(function () { $(this).attr("checked", !$(this).attr("checked")); }); }); }); 网页内容: <input type="radio" value="男" id="man" name="gender" /><label for="man">男</label><input type="radio" value="女" id="woman" name="gender" /><label for="woman">女</label><input type="radio" value="保密" id="secret" name="gender" /><label for="secret">保密</label><br /> <input type="checkbox" value="歌曲一" />歌曲一<input type="checkbox" value="歌曲二" />歌曲二<input type="checkbox" value="歌曲三" />歌曲三<input type="checkbox" value="歌曲四" />歌曲四<input type="checkbox" value="歌曲五" />歌曲五 <input type="button" value="设值" id="setValue"/> <input type="button" value="取值" id="getValue"/><br /> <input type="button" value="全选" id="allit"/><input type="button" value="全不选" id="littleit"/><input type="button" value="反选" id="revelit"/>