触发事件不适用于ajax加载的html

发布于 2024-09-02 11:53:03 字数 1480 浏览 3 评论 0原文

好吧,在我在焦点输出上创建的表中进行一行编辑后,它应该使用更新的数据重新加载整行,问题是触发事件在第一次加载后停止工作,因此在第一个之后完成的任何更改都不会保存。

我目前使用此代码

$(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-09-09 11:53:03

使用事件委托(livedelegate):

 // using .live
 $("td input").live("focusout", function() {
     ...

 // using .delegate
 $("table td").delegate("input", "focusout", function(){
     ...

当您按上述方式附加处理程序时,本质上您是:

将处理程序附加到事件
所有与当前匹配的元素
选择器,现在或将来。

换句话说,ajax 替换的元素将继续以这种方式触发最初绑定到它们的事件。

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.

In other words, ajax replaced elements will continue to fire the events initially bound to them in that way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文