get() 插入后 jquery 选择

发布于 2024-12-22 18:01:06 字数 499 浏览 2 评论 0原文

我通过对 php 页面的 get() 调用将行插入到表中,这是有效的。然后我想更新表的行号。

Jquery 更新除最近插入的行之外的所有行。

$("#insert_row").click(function () {
    $.get("print_row.php", function(data){
        $("#table").append(data);
    });
});

$("#insert_row").on("click", function () {
    var rowNumber = 1;
        $(".rowNumColumn").each(function () {
            $(this).text(rowNumber);
            rowNumber++;
        })    
});

我浏览该网站一段时间寻找这个问题的答案,解决方案似乎是 live() 或 on() 修饰符。但是我无法让它为我工作。

I'm inserting rows into a table via a get() call to a php page, which works. I then want to update the row numbers of the table.

Jquery updates all the rows except the most recently inserted one.

$("#insert_row").click(function () {
    $.get("print_row.php", function(data){
        $("#table").append(data);
    });
});

$("#insert_row").on("click", function () {
    var rowNumber = 1;
        $(".rowNumColumn").each(function () {
            $(this).text(rowNumber);
            rowNumber++;
        })    
});

I've browsed the site for a while looking for an answer to this, and the solution appears to be the live() or on() modifiers. However I can't get that to work for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

ゝ杯具 2024-12-29 18:01:06

您需要在 get 的回调中进行重新编号。现在,您正在 get 请求返回之前重新编号。 get 只是发出 ajax get 请求的快捷方式。 AJAX 是异步的,因此它不会等待请求返回后再继续。

$("#insert_row").click(function () {
    $.get("print_row.php", function(data){
        $("#table").append(data);

        var rowNumber = 1;
        $(".rowNumColumn").each(function () {
            $(this).text(rowNumber);
            rowNumber++;
        }) 
    });
});

You need to do the renumbering in the callback of the get. As it is now, you are renumbering prior to the get request returning. get is simply a shortcut for making an ajax get request. AJAX is asynchronous so it does not wait for the request to return before moving on.

$("#insert_row").click(function () {
    $.get("print_row.php", function(data){
        $("#table").append(data);

        var rowNumber = 1;
        $(".rowNumColumn").each(function () {
            $(this).text(rowNumber);
            rowNumber++;
        }) 
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文