<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> <br> <br><title></title> <br><script src="../conn/jsfile/jquery.js" type="text/javascript"></script> <br> <br> <br><form id="form1" runat="server"> <br>文本框 :<input type="text" id="txt" value="txt"><br> <br>单选按钮:<input type="radio" value="男" checked name="sex">男 <input type="radio" value="女" name="sex" checked>女<br> <br>复选框:<input type="checkbox" value="1" name="cc">1<input type="checkbox" value="2" checked name="cc">2<input type="checkbox" value="3" checked name="cc">3<br> <br>下拉框: <br><select id="sel" style="width: 100px"> <br><option value="yi">1</option> <br><option value="er" 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++) { <BR>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++) { <BR>if (checkboxs[i].checked) { <BR>alert(checkboxs[i].value); <BR>} <BR>} <BR>*/ <BR>/*获取下拉列表的选中项的值 <BR>方法一: <BR>alert(document.getElementById("sel").value); <BR>方法二: <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.value); <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> <br> <br> </div>