iT邦幫忙

0

[javascript/jquery] checkbox 的checked要怎麼false

  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20190531/20097057uAN58yY5uB.png
https://ithelp.ithome.com.tw/upload/images/20190531/20097057GGl4jxPPW3.png
https://ithelp.ithome.com.tw/upload/images/20190531/20097057ILr6MpYt7w.png
https://ithelp.ithome.com.tw/upload/images/20190531/20097057bTSFIlEVhh.png

html

echo'<div class="form-group col-md-12 contributory" >
     <label for="recipient-name" class="col-form-label" >請勾選繳費論文:</label>
     <div class="checkbox">';
for ($x = 0; $x <= $paper; $x++) { 

     echo'  &nbsp;&nbsp;<label><input type="checkbox" name="papernum[]" class="papernum" value="'.$array[$x].'">'.$array[$x].'</label>';
  
  }
echo'</div> </div> ';


echo'<div class="form-group col-md-6  contributory" >
    <label for="recipient-name" class="col-form-label" >論文報告(中文):</label>';
 
 echo' <div class="checkbox">';
for ($x = 0; $x <= $paper; $x++) { 

     echo'  &nbsp;&nbsp;<label><input type="checkbox" name="cpaper[]" class="epaper" value="'.$array[$x].'"disabled="disabled">'.$array[$x].'</label>';
  
  }
echo'</div> </div> ';         

js

/*投稿人*/
$("input[name='papernum[]']").change(function() {

          
          
           if(this.checked) {
           
           var i=$('.papernum').index(this);
           var allChkBox = document.getElementsByName('cpaper[]');
           allChkBox[i].disabled=false;                       
           var pay=$(".papernum:checked").length*1500;
           $("#allpay").html("總共需繳費新台幣:"+pay+"元整");
           $("#tpay").val(pay);
               
                   
    }      
  

   
   
    
    else{
    
            var i=$('.papernum').index(this);
            var allChkBox = document.getElementsByName('cpaper[]');
            allChkBox[i].disabled=true;
             allChkBox[i].prop('checked',false);
                   var pay=$(".papernum:checked").length*1500;
           $("#allpay").html("總共需繳費新台幣:"+pay+"元整");
              $("#tpay").val(pay);

                      
    }
});

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
dragonH
iT邦超人 5 級 ‧ 2019-06-01 00:30:31
最佳解答

codepen

大概修一下

你 lable 把 input 包住

應該是沒什麼用

然後你看起來有用bootstrap

那就不需要用

&nbsp;

來排版之類的

mayyola iT邦研究生 2 級 ‧ 2019-06-01 07:59:04 檢舉

d大的程式好難啊@O@ 我再消化一下 謝謝你

dragonH iT邦超人 5 級 ‧ 2019-06-01 12:01:52 檢舉

我加了一些註解你看會不會比較好懂

0
小魚
iT邦大師 1 級 ‧ 2019-05-31 23:53:38
var box = document.getElementById(id);
box.checked = false;
mayyola iT邦研究生 2 級 ‧ 2019-06-01 07:53:38 檢舉

謝謝~

不明
【**此則訊息已被站方移除**】
kyoe iT邦新手 5 級 ‧ 2019-06-04 10:10:50 檢舉

$('#foo').prop("checked", false);

我要發表回答

立即登入回答