触发事件不工作的AJAX加载HTML [英] Trigger events not working on ajax loaded html
问题描述
那么当你在一排在该表中我一直事件的内容它想重新加载更新的数据的整个行创建上编辑,事情是触发事件停止第一负荷工作后打完第一个做任何更改犯规得到保存。
Well After you edit in a row in this table i've created on focusout it suppose to reload the entire row with updated data, the thing is the trigger event stop working after the first load so any changes done after the first one doesnt get saved.
我目前使用这个code
I use currently this code
$(function () {
$.ajaxSetup ({
cache: false
});
$("td input").focusout(function() {
var defval = $(this).attr('title');
var value = $(this).attr('value');
var column = $(this).closest('td').attr('class')
var user = $('input[type=hidden]').attr('value');
var row = $(this).closest('tr').attr('id')
if(defval == value){
var state = 'Good Standing.';
}else{
var state = 'Will update spread sheet...';
var loadUrl = "./ajax/update.php";
$('#'+row+'').load(loadUrl, {row: row, user: user, column: column, value: value});
}
});
});
目前该行看起来像这样
and the row looks currently like this
<tr class="numbers" id="3">
<td class="a" align="right">3</td>
<td class="b"><input class="input" type="text" title="1750" value="1750"/></td>
<td class="c"><input class="input" type="text" title="2100" value="2100"/></td>
<td class="d"><input class="input" type="text" title="0" value="0"/></td>
<td class="e"><input class="input" type="text" title="0" value="0"/></td>
<td class="f">3.5</td>
<td class="g"><input class="input" type="text" title="0" value="0"/></td>
</tr>
任何的帮助我会得到它是pciated大大AP $ P $
any aid i'll get it is greatly appreciated
关于
推荐答案
Use event delegation (live or delegate):
// using .live
$("td input").live("focusout", function() {
...
// using .delegate
$("table td").delegate("input", "focusout", function(){
...
当您将一个处理方法同上,实际上你是:
When you attach a handler as above, essentially you are:
附加一个处理程序的事件 这符合当前的所有元素 选择,现在还是在未来。
Attaching a handler to the event for all elements which match the current selector, now or in the future.
在换句话说,AJAX替换元素将会继续正常触发初始绑定到这些以这种方式的事件。
In other words, ajax replaced elements will continue to fire the events initially bound to them in that way.
这篇关于触发事件不工作的AJAX加载HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!