[轉]如何通過Jquery擷取radio的值

來源:互聯網
上載者:User

如何通過Jquery簡單又快速的擷取一組radio的取值呢?

Jquery老的版本
var_name = $(“input[@name='radio_name']:checked”).val();
Jquery 1.3以後的版本
var_name = $(“input[name='radio_name']:checked”).val();

賦值:$("#fe-detail input[name='Options'][value=1]").attr("checked",true).click();

區別是老版本有個@.

 

myCode:

function getra(){
 
       var_name = $("input[name='isSpecialCnt']:checked").val();
       //alert(var_name);
       if(var_name=='1'){
       $("#isSpecialCntYes").show();
       $("#isSpecialCntNo").hide();
       }
       if(var_name=='0'){
       $("#isSpecialCntYes").hide();
       $("#isSpecialCntNo").show();
       }
 }

<tr>
  <td class="dataTable_deatil_title">是否特殊箱</td>
  <td>
  <s:radio name="isSpecialCnt" list="#application.optionsService.makeParamMap()" onclick="getra()"> </s:radio>
  
  
  </td>
  <td class="dataTable_deatil_title">開航日期</td>
  <td><s:textfield id="sailingDay" name="sailingDay"  size="10"
       value="%{departureDate == null ? '' : getText('global.format.date',{sailingDay})}" />
      <img id="img_sailingDay"
       src="<c:url value="/widgets/calendar/images/calendar.gif"/>"
       width="22" height="19" align="absmiddle" /></td>
  
  </tr>

  <tr id="isSpecialCntYes" style="display:none">
  
  <td class="dataTable_deatil_title">櫃型</td>
  <td><s:select name="specialCntType" list="#application.optionsService.getParamsOptions('PTL_TRADE_CNTTYPE')" headerKey=""
                  headerValue="%{getText('option.empty.text')}"></s:select></td>
  </tr>
  
  <tr id="isSpecialCntNo" style="display:none">
  
  <td class="dataTable_deatil_title">櫃型</td>
  <td><s:textfield name="specialCntType" /></td>
  </tr>

 

參考資料:

http://www.cnblogs.com/dexter2003/archive/2011/01/03/1924539.html

http://www.jb51.net/article/20336.htm

http://blog.163.com/da7_1@126/blog/static/104072678201102241526196/

http://apps.hi.baidu.com/share/detail/23719859

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.