复制代码 代码如下:
<asp:RadioButtonList runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
<div>
<a href="javascript:">通过Type获得RadioButtonList的Value</a>
</div>
<br />
<div>
<input type="radio" value="A" />A<br />
<input type="radio" value="B" />B<br />
<input type="radio" value="C" />C<br />
<input type="radio" value="D" />D<br />
</div>
<div>
<a href="javascript:">通过Name获得Radio的Value</a>
</div>
<br />
<br />
<div>
<input type="checkbox" value="A" />A<br />
<input type="checkbox" value="B" />B<br />
<input type="checkbox" value="C" />C<br />
<input type="checkbox" value="D" />D<br />
</div>
<div>
<a href="javascript:">通过Name获得CheckBox的Value</a> <a href="javascript:">全选</a> <a href="javascript:">反选</a>
</div>
<br />
<br />
<div>
<select multiple="multiple">
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="A3">A3</option>
<option value="A4">A4</option>
</select>
</div>
<div>
<a href="javascript:">获得Multiple的Value</a> <a href="javascript:">添加</a> <a href="javascript:">移除</a>
</div>
<br />
<br />
<div>
<select>
<option value="B1">B1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="B4">B4</option>
</select>
</div>
<div>
<a href="javascript:">获得Select的Value</a> <a href="javascript:">添加</a> <a href="javascript:">移除</a>
</div>
jQuery代码
复制代码 代码如下:
<script type="text/javascript">
$(document).ready(function () {
//获得RadioButtonList的Value
$("#btnGetRadioButtonListValue").click(function () {
if ($("input[type=radio]:checked").val() == null) {
alert("请选择");
return false;
}
alert($("input[type=radio]:checked").val());
});
//获得Html的Radio的Value
$("#btnGetRadioValue").click(function () {
if ($("input[name='radioSelect']:checked").val() == null) {
alert("请选择");
return false;
}
alert($("input[name='radioSelect']:checked").val());
});
//获得CheckBox的Value
$("#btnGetCheckBoxValue").click(function () {
var values = "";
$("input[name='chkSelect']").each(function () {
if ($(this).attr("checked")) {
values += $(this).val() + ",";
}
});
if (values == "") {
alert("请选择");
return false;
}
values = values.substring(0, values.length - 1); //去掉尾部,
alert(values);
});
//全选
$("#btnSelectAllOn").click(function () {
$("input[name='chkSelect']").each(function () {
$(this).attr("checked", true);
});
});
//返选
$("#btnSelectAllOff").click(function () {
$("input[name='chkSelect']").each(function () {
$(this).attr("checked", false);
});
});
//获得Multiple的值
$("#btnGetMultipleValue").click(function () {
var values = "";
$("#multiple1 option:selected").each(function () {
values += $(this).val() + ",";
})
values = values.substring(0, values.length - 1); //去掉尾部,
alert(values);
});
//添加Multiple的Option
$("#btnAddMultipleOption").click(function () {
$("#multiple1").append("<option value='AX'>AX</option>");
});
//移除Multiple所选Option
$("#btnRemoveMultipleOption").click(function () {
$("#multiple1 option").remove("option:selected");
});
//获得Select的值
$("#btnGetSelectValue").click(function () {
alert($("#select1 option:selected").val());
});
//添加Select的Option
$("#btnAddSelectOption").click(function () {
$("#select1").append("<option value='BX'>BX</option>");
});
//移除Select所选Option
$("#btnRemoveSelectOption").click(function () {
$("#select1 option").remove("option:selected");
});
});
</script>
您可能感兴趣的文章: