簡體   English   中英

使用Jquery的Rails App:只允許選擇一個復選框(haml)

[英]Rails App using Jquery: Only allowed to select one checkbox (haml)

我有一個信用卡選項(選中此框后,您可以選擇美國運通卡,萬事達卡,發現卡或Visa卡)。 如果你取消它,它就是隱藏的。

同樣適用於檢查選項:如果您單擊它,它會顯示發送支票的地址,如果您取消選中它會消失。

所以前兩個功能正在按預期工作。 現在我想能夠做到這一點,所以你不能點擊支票和信用卡。 第三個功能有什么問題? 一位朋友建議我的HAML中有太多div(請參閱gist https://gist.github.com/2654244了解內容)。

是的我知道我應該使用單選按鈕:)稍后會改變。

= content_for :javascripts do
  :javascript
      $(function(){
        $("#cc_checkbox").click(function(){
        if($(this).children("input").is(':checked')){
          $(this).next().show();
          }
        else{
        $(this).next().hide();
        }
      });
     })

     $(function(){
       $("#check_checkbox").click(function(){
       if($(this).children("input").is(':checked')){
     $(this).next().show();
     }
  else{
     $(this).next().hide();
     }
   });
 })

     $(function() {
       var $paymentSplit = $('input.paymentSplit');
         $paymentSplit.click(function() {
           $paymentSplit.removeAttr('checked');
           $(this).attr('checked', true);
         });
      });

使它們成為單選按鈕而不是復選框。 任何時候都只能選擇一個同名的單選按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM