日期:2014-05-18  浏览次数:20439 次

在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>