使用 JavaScript 新增圖示來切換按鈕事件
P粉541565322
P粉541565322 2023-09-05 00:08:30
0
1
396
<p><pre class="brush:js;toolbar:false;">函數toggledDeleteAllBtn(){ if( $('.customer_checkbox:checked').length > 0){ $('#sel_button').text('刪除所有選取的(' $('.customer_checkbox:checked').length ')'); }別的{ $('#sel_button').text('刪除所有選取的'); } } </前> <pre class="brush:html;toolbar:false;"> <tr id=「sid」> 第<第>ID個 第<第>個電話號碼個 <第>備註 <第>日期 <第></第> <輸入類型=“複選框” name="main-checkbox"></th> <th><按鈕類別=“btn btn-danger btn-sm” id=“sel_button”名稱=“sel_button” ><i class=“glyphicon glyphicon-trash” id="trash_icon"></i>刪除所有</button></th> </前>

請問如何將 iclass 中的圖示填入新增至函數 toggleDeleteAllBtn()修改,以便顯示無論進行什麼更改,圖標始終?(需要在toggleDeleteAllBtn()中進行一些) 謝謝!</p>

P粉541565322
P粉541565322

全部回覆(1)
P粉106301763

我以 Mamun 的答案作為參考,並用回了我喜歡的圖示。 (剛剛意識到 Mamun 已經刪除了他原來的答案,因為他使用的是 font Awesome 而不是 glyphicon。無論如何,非常感謝你給我這些想法!)

function toggledDeleteAllBtn() {
  if ($('.customer_checkbox:checked').length > 0) {
    $('#sel_button').html('<i class="glyphicon glyphicon-trash" </i>Delete all selected(' + $('.customer_checkbox:checked').length + ')');
  } else {
    $('#sel_button').html('<i class="glyphicon glyphicon-trash" </i>Delete all selected');
  }
}
$(document).on('click', '.customer_checkbox', toggledDeleteAllBtn);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js">
</script>
<script src="plugins/Jquery-Table-Check-All/dist/TableCheckAll.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js">
</script>

<table>
  <tr id="sid">
    <th> ID </th>
    <th> phone number </th>
    <th> remarks </th>
    <th> date </th>
    <th></th>
    <th><input type="checkbox" class="customer_checkbox" name="main-checkbox"></th>
    <th><button class="btn btn-danger btn-sm" id="sel_button" name="sel_button"><i class="glyphicon glyphicon-trash" </i> Delete all selected</button></th>
  </tr>
</table>
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!