注册onclick问题 [英] register onclick problem

查看:78
本文介绍了注册onclick问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题:


我正在动态地添加和删除行,

每一行都有它的id并删除按钮


当我删除一行时,我继续下一行并更新他们的ID

我还需要更新删除行按钮。


问题是该按钮有onclick =" deleteRow(rowId)"

当我删除一行并更新所有下一个元素时


所有人都使用相同的ID(最后一个的id)调用deleteRow

展开 | 选择 | Wrap | 行号

解决方案

设置onclick一个元素,以实现其他元素点击


我正在动态地添加和删除行,

每一行都有它的id和删除按钮。

当我删除一行时
我更新所有下一行ID

和onclick functino以使用新ID调用deleteRow(rowID)。


所有下一个元素onclick函数

调用具有相同ID的deleteRow函数(最后一次迭代的id)


例如:

所有按钮调用deleteRow(2)


[PHP] i = currentID;

while(i< ElementsCounter){

newID = i - 1;

document.getElementById(" delete" + i).id =" delete" + newID;

document.getElementById(" delete" + newID).onclick = function(){deleteRow(newID); };

} [/ PHP]


感谢提前


合并重复的帖子。


如何传递this改为删除函数?



合并重复的线程。


如何传递"这"改为删除功能?



如果我传递obj本身我怎样才能获得行ID?


还有另一种添加onlick的方法事件


I ran into a strange problem:

I''m adding and removing rows dynamicly,
each row has it''s id and remove button

when I removing a row i go on all the next rows and update their ID
I also need to update the delete row button.

the problem is that the button has onclick="deleteRow(rowId)"

and when I remove a row and update all the next elements

all of them are calling the deleteRow with the same ID (the id of last one)

Expand|Select|Wrap|Line Numbers

解决方案

setting onclick of one element happans to effect other elements onclick

I''m adding and removing rows dynamicly,
each row has it''s id and remove button.

when I removing a row i update all the next rows IDs
and the onclick functino to call the deleteRow(rowID) with the new ID.

All next elements onclick function
is calling the deleteRow function with the same ID (the id of last iteration)

for example:
all of the button call deleteRow(2)


[PHP]i = currentID;
while(i < ElementsCounter){
newID = i - 1;
document.getElementById("delete"+i).id = "delete"+newID;
document.getElementById("delete"+newID).onclick = function(){ deleteRow(newID); };
}[/PHP]

Thanks from advance


Merged duplicate threads.

How about passing "this" to the delete function instead?


Merged duplicate threads.

How about passing "this" to the delete function instead?


if I pass the obj itself how can i get the row ID?

there is another way to add an onlick event?


这篇关于注册onclick问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆