私はjQueryが初めてです。このように動的にチェックされたときに、あるテーブルから別のテーブルに製品を追加するコードを作成しましたFIDDLE
。フィドルでわかるように、このコードはうまく機能しています。
今、私は ajax を使用してこの製品リスト (表 2) を動的に生成することにより、このコードを操作しましたが、このコードは機能しません..
この欠陥について考えてみると、すべての CSS および JS スクリプトがページの読み込みとともに読み込まれると考えていますが、このチェックボックス (表 2) が動的に読み込まれるため、JS はこれを楽しまないのです ....
動的にロードされた入力フィールドでイベント関数を起動する方法...このスクリプトを改善したいだけです:JQUERY 1.6.4
これが私の見解です:
<div class="_25">
<?php echo form_dropdown('class', $dropdown_class,'','id="clas"'); ?>
</div>
<div class="_25">
<?php echo form_dropdown('section',$dropdown_section); ?>
</div>
<table class="table" border="1">
<thead><tr>
<th>Select</th>
<th>Cause</th>
<th>Monthly Charge</th>
</tr></thead>
<tbody id="selectedServices"></tbody>
<tr>
<td>Total-</td>
<td>Fee</td>
<td id="total">1500</td>
</tr>
</table>
<!-- product list (will generate dynmiclly)like tble 2 in fiddle -->
<table id="abcd" class="table" border="1">
<thead><tr>
<th>Select</th>
<th>Cause</th>
<th>Monthly Charge</th>
</tr></thead>
<tbody id="name_sec">
<!-- here your dat will appear as per selection of class ajax check the below function and related controller mthod
the value will come with chk box for selection ad prepering the data-->
</tbody>
</table>
これが私のスクリプトです:
<script language="javascript">
jQuery(function ($) {
$("#clas").change(function() {
var send_data=$("#clas").val();
$.ajax({
type:"post",
url:"show_additional_fee_chkbox_select",
data:"send_data_post_for_chkbox="+send_data,
success:function(data){
$("#name_sec").html(data);
}
});
});
$(":checkbox").change(function () {
// Toggle class of selected row
$(this).parent().toggleClass("rowSelected");
// Get all items name, sum total amount
var sum = 1500;
var arr = $("#abcd :checkbox:checked").map(function () {
sum += Number($(this).parents('tr').find('td:last').text());
return $(this).parents('tr').clone();
}).get();
// Display selected items and their sum
$("#selectedServices").html(arr);
$("#total").text(sum);
$('#selectedServices :checkbox').change(function() {
$('#selectedServices :checkbox:unchecked').parents('tr').remove();
});
});
});
</script>
そして私のコントローラー:
public function show_additional_fee_chkbox_select()
{
$class=$_POST['send_data_post_for_chkbox'];
//here goes ur process to display list of extra/additional fee
$extra_fee_list='';
$sql2="SELECT * FROM fee_additional_fee where class=?";
$query2 = $this->db->query($sql2,$class);
foreach ($query2->result_array() as $row2) {
$extra_fee_list=$extra_fee_list.'
<tr>
<td>
<input type="checkbox" id="selectedServices" class="checkBoxClass" name="additional_fee_code[]" value="'.$row2['id'].'"> Select</input>
</td>
<td>'.$row2['cause_addition_fee'].'</td>
<td>'.$row2['fee'].'</td>
</tr> ';
// here again plz take input in arry ----additional_fee_code will work for next method (cal_total_extra_fee())
}
echo $extra_fee_list;
}