get() 插入后 jquery 选择
我通过对 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
get
的回调中进行重新编号。现在,您正在get
请求返回之前重新编号。get
只是发出ajax
get 请求的快捷方式。 AJAX 是异步的,因此它不会等待请求返回后再继续。You need to do the renumbering in the callback of the
get
. As it is now, you are renumbering prior to theget
request returning.get
is simply a shortcut for making anajax
get request. AJAX is asynchronous so it does not wait for the request to return before moving on.