我有一个带有复选框的薪给数据表,以及一个用于填充chantiers的选择,以及一个按钮updateAll,当我检查薪资行并在“选择并单击按钮updateAll”中选择“chantier”时,“薪酬chantier”检查“在select中按值选择修改”。注意:在不改变select值的情况下,即在我的示例中不碰<option value="1">azilal</option> not <option value="azilal">azilal</option>,它会将azilal更改2,但我想通过tizgui更改azilal,这只是一个例子
数据表
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<select class="form-control" id="chantier">
<option selected disabled>Select Location</option>
<option value="1">azilal</option>
<option value="2">asfalou</option>
<option value="3">tizgui</option>
</select>
<button class="btn btn-theme update-all" data-url="">Update All</button>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th><input type="checkbox" id="check_all"></th>
<th>nom prenom</th>
<th>cin</th>
<th>matricule</th>
<th>chantier</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td><input type="checkbox" class="checkbox" name="customer_id[]" value="1" /></td>
<td>MARZOUK NAJIB</td>
<td>Pa130191</td>
<td>2925019599</td>
<td value="1">azilal</td>
</tr>
<tr id="2">
<td><input type="checkbox" class="checkbox" name="customer_id[]" value="2" /></td>
<td>achraf bourki</td>
<td>pa5000</td>
<td>202020</td>
<td value="2">tizgui</td>
</tr>
</tbody>
</table>jQuery
<script type="text/javascript">
$(document).ready(function () {
$('#check_all').on('click', function(e) {
if($(this).is(':checked',true))
{
$(".checkbox").prop('checked', true);
} else {
$(".checkbox").prop('checked',false);
}
});
$('.checkbox').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox').length){
$('#check_all').prop('checked',true);
}else{
$('#check_all').prop('checked',false);
}
});
$('.update-all').on('click', function(e) {
if(confirm("Are you sure you want to update this?"))
{
var id = [];
var chantier;
$(':checkbox:checked').each(function(i){
id[i] = $(this).val();
});
if(id.length === 0){
alert("Please Select atleast one checkbox");
}else{
let chantier = $('#chantier').val();
for(var i=0; i<id.length; i++)
{
$('tr#'+id[i]).find('td:last-child').html(chantier);
}
}}
else{
return false;
}
});
});
</script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>发布于 2020-02-13 12:23:39
在javascript内部,您选择的是#chantier的所选选项的值,而不是它的文本。
您所需要做的就是将这一行更改如下:
老台词:
let chantier = $('#chantier').val();以下文取代:
let chantier = $('#chantier option:selected').html();https://stackoverflow.com/questions/60206864
复制相似问题