<div class="codetitle"> <span><a style="CURSOR: pointer" data="57549" class="copybut" id="copybut57549" onclick="doCopy('code57549')"><u>复制代</u></a></span>代码如下:</div> <div class="codebody" id="code57549"> <br><html xmlns="http://www.w3.org /1999/xhtml"> <BR><head runat="server"> <br><title></title> <br><script src="../conn/jsfile/jquery.js" type="text/javascript"></script> <br></head> <br> <br><form id="form1" runat="server"> <br>文本框 :<input type="text" id="txt" value="txt" /><br /> <br>单选按钮:<input type="radio" value="男" Checked="checked" name="sex" />男 <input type="radio" value="女" name=" sex" selected="checked"/>女<br /> <br>复选框:<input type="checkbox" value="1" name="cc"/>1<input type="checkbox" value="2" selected="checked" name="cc " />2<input type="checkbox" value="3" selected="checked" name="cc" />3<br />; <BR>下拉框: <BR><select id="sel" style="width: 100px"> <br><option value="yi">1</option> <br><option value="er" selected="selected">2</option> <br><option value="san">3</option> <br></select> <br><script language="javascript" type="text/javascript"> <br>/*------------------------------------------ ---javascript-------------------------------------------*/ <br>/* 获取文本框的值 <br>alert(document.getElementById("txt").value); <br>*/ <br>/*获取单选按钮的值 <br>var radios = document.getElementsByName("sex"); <br>var n = radios.length; <br>for (var i = 0; i <n i>if (radios[i].checked) { <br>alert(radios[i].value); <br>} <br>} <br>*/ <br>/*获取复选框中选中の值的組み合わせ 1,2,3,4 <br>var checkboxs = document.getElementsByName("cc"); <br>var n = checkboxs.length; <br>for (var i = 0; i <n i>if (checkboxs[i].checked) { <br>alert(checkboxs[i].value); <br>} <br>} <br>*/ <br>/*取下拉列表の選択中项の値 <br> 方法 1: <br>alert(document.getElementById("sel").value); <br>方法 2: <br>var sel = document.getElementById("sel"); <br>alert(sel.options[sel.selectedIndex].value); <br>*/ <br>/*----------------------------------------------------- --------jquery------------------------------------------ --*/ <br>/*获取文本框的值 <br>alert($("#txt").val()); <br>*/ <br>/*获取单选框选中项的值 <br>alert($(":radio[name='sex']:checked").val()); <br>单选框赋值 设置选中项 <br>$(":radio[name='sex']").val(["男"]); <br>*/ <br>/*获取复选框的值 <br>$(":checkbox[name='cc']:checked").each(function(i) { <br>alert(this.値);<br>}); <br>复选框赋值 选中这几项 <br>$(":checkbox[name='cc']").val(["1", "2", "3"]); <br>*/ <br>/*获取下拉列表的值 <br>alert($("#sel").val()); <br>获取下拉列表の文本 <br>alert($("#sel option:selected").text()); <br>*/ <br></script> <br></form> <br></body> <br></html> <br></n></n> </div>