在上图中,我使用以下代码动态填充行:
false
现在我想每当我添加行时,测试名称将根据用户通过ajax调用选择的测试类别进行更改,但我遇到的问题是只有第一行通过ajax调用更改但是是否休息。 现在ajax调用的代码是:
jQuery(function($) {
var $button = $('#add-row'),
$row =$('tr.timesheet-row').clone();
$button.click(function() {
$row.clone(true).appendTo('tbody').val("");
});
});
这是我的观点部分
<script type="text/javascript">
$(document).ready(function() {
// function myAjaxFunction(elem)
//{
$('.changeAjax').change(function() {
var selTestCatg = $(this).val();
$.ajax({
url: "<?php echo base_url() ?>index.php/addPatientDetails/selectTestName",
type: "POST",
data: "testCategory="+selTestCatg,
success: function(data){
$('#testName').html(data);
}
});
});
//}
});
</script>
这是我的数据库部分:
<tbody>
<tr class="timesheet-row">
<td><input class="case" type="checkbox"/></td>
<!--<td><input type="text" data-type="doctorName" name="doctorName[]" id="doctorName_1"
class="form-control autocomplete_txt" autocomplete="off"></td>-->
<td>
<select name="doctorName[]" id="doctorName" class="form-control autocomplete_txt">
<option selected="selected" value="">Select Doctor Name</option>
<?php
foreach($listDoctor as $row1)
{
?>
<option value="<?= $row1['id'] ?>"><?= $row1['name'] ?></option>
<?php
}
?>
</select>
</td>
<td>
<select name="testCatg[]" id="testCatg" class="form-control changeAjax">
<option selected="selected" value="">Select Test Type</option>
<?php
foreach($listTestType as $row2)
{
?>
<option value="<?= $row2['id'] ?>"><?= $row2['test_type'] ?></option>
<?php
}
?>
</select>
</td>
<td><!--<input type="text" name="testName[]" id="testName" class="form-control changesNo"
autocomplete="off" ondrop="return false;" onpaste="return false;">-->
<select name="testName[]" id="testName" class="form-control autocomplete_txt">
<option selected="selected" value="">Select Test Name</option>
</select>
</td>
<td><input type="number" name="testPrice[]" id="testPrice_1" class="form-control totalLinePrice"
autocomplete="off" onkeypress="return IsNumeric(event);" onpaste="return false;" value=""></td>
</tr>
</tbody>
这是我的控制器部分:
public function getTestName()
{
$this->db->select('test_details.*,test_catg.test_type as TestCategory');
$this->db->from('test_details');
$this->db->join('test_catg','test_catg.id = test_details.test_catg_id');
//$this->db->where('test_details.test_catg_id',$testCatgID);
$query3 = $this->db->get();
if($query3->num_rows() > 0)
{
$result3 = $query3->result_array();
return $result3;
}
else
{
return FALSE;
}
}