触发事件不适用于ajax加载的html
好吧,在我在焦点输出上创建的表中进行一行编辑后,它应该使用更新的数据重新加载整行,问题是触发事件在第一次加载后停止工作,因此在第一个之后完成的任何更改都不会保存。
我目前使用此代码
$(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});
}
});
});
,该行目前看起来像这样,
<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>
我将得到任何帮助,非常
感谢
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.
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>
any aid i'll get it is greatly appreciated
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用事件委托(live 或 delegate):
当您按上述方式附加处理程序时,本质上您是:
换句话说,ajax 替换的元素将继续以这种方式触发最初绑定到它们的事件。
Use event delegation (live or delegate):
When you attach a handler as above, essentially you are:
In other words, ajax replaced elements will continue to fire the events initially bound to them in that way.