Jquery获取input的内容

1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head runat="server">
3 <title>GetInputValue</title>
 1  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
2 <script type="text/javascript">
3 var message = "";
4 function showMessage() {
5 message += "Document File is " + $(":file").val() + "<br />";
6 message += "Radio Value is " + $("input[name='rView']:checked").val();//获取radio选中项
7 message += "<br/>CheckBox Value is ";
8 $("input[name='cView']:checked").each(function () {
9 message += $(this).val() + ",";
10 });//获取checkbox选中项
11 message = message.substring(0, message.length - 1);
12 message += "<br/>Select value is " + $("#sView").val();//获取select选中项
13 message += "<br/>Select value is " + $("input:text").val();
14 $("p").html("").html(message);
15 message = "";
16 }
17 function setSel(value) {
18 $("#sView").val(value);
19 }
20 function setRad(value) {
21 $("input[name='rView'][value=" + value + "]").attr("checked", "true");
22 }
23 function setChk(value) {
24 var a = value.split(",");
25 for (var i = 0; i < a.length; i++) {
26 $("input[name='cView'][value=" + a[i] + "]").attr("checked", "true");
27 }
28 }
29 </script>
</head>
<body>
<p>
</p>
<div>
<table width="100%">
<tr>
<td>
<input type="radio" name="rView" value="1" />显示
<input type="radio" name="rView" value="0" />不显示
</td>
</tr>
<tr>
<td>
<input type="text" name="" value="1" />显示
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="cView" value="1" />A
<input type="checkbox" name="cView" value="0" />B
</td>
</tr>
<tr>
<td>
<select id="sView">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
</td>
</tr>
<tr>
<td>
<input id="file1" type="file" />
</td>
</tr>
</table>
</div>
<div>
<input type="button" value="获取值" onclick="showMessage()" />
<input type="button" value="设置Select值为B" onclick="setSel(2)" />
<input type="button" value="设置CheckBox值为显示" onclick="setChk('1,0')" />
<input type="button" value="设置Radio值为不显示" onclick="setRad(0)" />
</div>
</body>
</html>




 

posted @ 2012-03-09 16:58  JerryT  阅读(4746)  评论(0编辑  收藏  举报