读书人

在JS中判断选中那个radio解决方案

发布时间: 2012-04-13 13:50:24 作者: rapoo

在JS中判断选中那个radio
<asp:RadioButton ID="importanty" runat="server" Text="重要" GroupName="GR" OnCheckedChanged="Radio_Change" AutoPostBack="true"/>

<asp:RadioButton ID="importantn" runat="server" Text="一般" GroupName="GR" Checked="true" OnCheckedChanged="Radio_Change1" AutoPostBack="true"/>

怎么在JS中判断选中那个,查看源码如下


<td class="td2">
<input id="ctl00_ContentPlaceHolder1_importanty" type="radio" name="ctl00$ContentPlaceHolder1$GR" value="importanty" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$importanty\',\'\')', 0)" /><label for="ctl00_ContentPlaceHolder1_importanty">重要</label>

<input id="ctl00_ContentPlaceHolder1_importantn" type="radio" name="ctl00$ContentPlaceHolder1$GR" value="importantn" checked="checked" /><label for="ctl00_ContentPlaceHolder1_importantn">一般</label>


</td>

[解决办法]

function check_radio(){
var chkObjs = document.getElementsByName("rdOperatingMethods");


if(chkObjs[0].checked){

---------------执行的语句---
}
else if(chkObjs[1].checked){

---------------执行的语句---

}
if(chkObjs[2].checked){
---------------执行的语句---

}

}






</script>

[解决办法]
JQ

JScript code
    <script type="text/javascript">        $(":radio").each(function () {            if ($(this).attr("checked") == "true" || $(this).attr("checked") == "checked")            { }        });    </script>
[解决办法]
探讨
JQ

JScript code

<script type="text/javascript">
$(":radio").each(function () {
if ($(this).attr("checked") == "true" || $(this).attr("checked") == "checked")
……

[解决办法]
支持使用Jquery,

<script type="text/javascript">
$(":radio").each(function () {
if ($(this).attr("checked") == "true" || $(this).attr("checked") == "checked")
{ }
});
</script>

读书人网 >asp.net

热点推荐