Utilisation de JavaScript pour ajouter une icône pour basculer les événements du bouton
P粉541565322
P粉541565322 2023-09-05 00:08:30
0
1
484
<p><pre class="brush:js;toolbar:false;">fonction toggledDeleteAllBtn(){ si( $('.customer_checkbox:checked').length > 0){ $('#sel_button').text('Supprimé tous les éléments sélectionnés('+$('.customer_checkbox:checked').length+')'); }autre{ $('#sel_button').text('Supprimer tous les éléments sélectionnés'); } } ≪/pré> <pre class="brush:html;toolbar:false;"> <tr id="sid"> <th>ID</th> <th>numéro de téléphone</th> <th>remarques</th> <th>date</th> <th></th> <th><input type="case à cocher" name="case à cocher principale"></th> <th><button class="btn btn-danger btn-sm" id="sel_button" name="sel_button" ><i class="glyphicon glyphicon-trash" id="trash_icon"></i>Supprimer tout </bouton></th> ≪/tr> ≪/pré> <p>请问如何将 iclass 中的图标垃圾添加到函数 <code>toggleDeleteAllBtn()</code> 中,以便无论进行什么更改,图标始终显示? (需要在<code>toggleDeleteAllBtn()</code> 谢谢!</p>
P粉541565322
P粉541565322

répondre à tous(1)
P粉106301763

J'ai utilisé la réponse de Mamun comme référence et je suis revenu aux icônes qui me plaisaient. (Je viens de réaliser que Mamun avait supprimé sa réponse originale parce qu'il utilisait la police Awesome au lieu de glyphicon. Quoi qu'il en soit, merci beaucoup de m'avoir donné ces idées !)

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>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!