<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="../myjs/jquery-1.4.2-vsdoc.js" type="text/javascript"></script> <script type ="text/javascript" > $(function() { $(":button[value=取值]").click(function() { var checkvalue = ""; //var s = $("input[name=a]:checked").val(); var s = $(":radio:checked").val(); $("input[type=checkbox]:checked").each(function() { checkvalue += $(this).val(); }); var selectvalue = ""; $("select :selected").each(function() { selectvalue += $(this).val(); }); alert("checkvalue:" + checkvalue + "radiovalue:" + s + "selectvalue:" + selectvalue); }); $(":button[value=设置]").click(function() { $("input[name=a]").val(["娱乐1"]); $("input[type=checkbox]").val(["篮球", "游戏"]); $("select").val(["篮球", "游戏"]); }); });
</script> </head> <body> <input type ="checkbox" id="footbal" value="足球"/><label for ="footbal">足球</label><br /> <input type ="checkbox" value="篮球" />篮球<br /> <input type ="checkbox"value="看书" />看书<br /> <input type ="checkbox" value="游戏"/>游戏<br /><hr /> <input type ="radio" name ="a" id="b" value ="娱乐1" /><label for ="b">娱乐1</label><br /> <input type ="radio" name ="a" value ="娱乐2" />娱乐2<br /> <input type ="radio" name ="a" value ="娱乐3" />娱乐3<br /> <hr /> <select multiple ="multiple" > <option value ="篮球">篮球</option> <option value ="足球">足球</option> <option value ="看书">看书</option> <option value ="游戏">游戏</option> </select> <input type ="button" value="取值"/> <input type ="button" value="设置"/> </body> </html>