我在codeigniter項目中觸發事件時遇到問題。我想在我的頁面中動態加載表格。該表通過ajax調用從我的控制器返回。我想在該表中的一個範圍內觸發點擊事件。我在很多方面都嘗試過這種方式,但它不起作用。我在這裏附上我的代碼。請幫助我找到解決方案。在Ajax響應元素上觸發JQuery事件
控制器:鑑於
$str = '<table>
<tr>
<td class="cost date" id="date_'.$request['SupplyID'].'">
<span class="editable" style="display: none;">
<input type="text" class="expiry" autocomplete="off" data-date-id="date_'.$request['SMSSupplyID'].'">
</span>
<span class="cnt" style="display: inline;">Choose</span>
</td>
</tr>
</table>';
echo $str;
腳本:
function loadmore()
{
var url;
url = '/SMS/SMS/loadMoreRequests';
$.ajax({
type: 'post',
url: url,
data: {
limit:val
},
success: function (response) { console.log(response);
$("#requestListTable").html(response);
val +=10;
}
});
}
$('.date').find('.cnt').on('click', function(){
console.log(1); // for testing
});
我嘗試了以下的變化,但沒有用
1)
$('.date').find('.cnt').live('click', function(){
console.log(1); // for testing
});
2)
$('.date').find('.cnt').click(function(){
console.log(1); // for testing
});
試試我的回答我希望它能解決你的問題。 –