使用事件处理程序交换元素
我有以下结构,
<div id="mainblock">
<div id="inner1">
some content in inner1
</div>
<div id="innersub1">
<input type="submit" id="go" value="go">
<input type="submit" id="delete" value="delete">
</div>
<div id="inner2">
some content in inner2
</div>
<div id="innersub2">
<input type="submit" id="go" value="go">
<input type="submit" id="delete" value="delete">
</div>
我需要在inner1和inner2 div之间交换内容,包括id。所以,id的变化就像inner1变成inner2,innersub1变成innersub2,反之亦然。我已经能够使用 jquery 做到这一点。现在,“转到”和“删除”按钮已附加处理程序。但是,现在当我单击“编辑”时,它会显示交换之前的先前内容。那么,我应该如何重新附加这些处理程序?我可以通过其他方式处理与处理程序的内容交换吗?
谢谢
I have following structure
<div id="mainblock">
<div id="inner1">
some content in inner1
</div>
<div id="innersub1">
<input type="submit" id="go" value="go">
<input type="submit" id="delete" value="delete">
</div>
<div id="inner2">
some content in inner2
</div>
<div id="innersub2">
<input type="submit" id="go" value="go">
<input type="submit" id="delete" value="delete">
</div>
I need to exchange content between inner1 and inner2 div inluding ids. So, the id's change like inner1 becomes inner2,innersub1 becomes innersub2, and viceversa. I have been able to do this, using jquery. Now, go and delete buttons have attached handlers. But, now when I click "edit", it shows previous content before exchange. So, how should I reattach these handlers? Can I handle this swapping of content with handlers in some other way?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以手动(在代码中)分离重新附加它们。或者,您可以隐藏或取消隐藏所需的按钮,并保持事件处理程序不变。
You can manually (in code) detach reattach them. Alternately you can just hide an unhide the buttons you need and leave the event handlers as they are.