zoukankan
html css js c++ java
dom 的添加或事件绑定
dom 的添加或事件绑定
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>test-del</title> <style> p{ 400px; margin:0 auto; } ins{ cursor:pointer; text-decoration:none; padding-left:20px; } </style> </head> <body> <div> <div id="list"> <p><span>1</span> <ins>delete</ins> </p> <p><span>2</span> <ins>delete</ins> </p> <p><span>3</span> <ins>delete</ins> </p> <p><span>4</span> <ins>delete</ins> </p> <p><span>5</span> <ins>delete</ins> </p> <p><span>6</span> <ins>delete</ins> </p> </div> </div> <p><a id="add" href="javascript:void(0);">Add</a></p> </body> </html> <script type="text/javascript"> // get elem function id(){ return document.getElementById(arguments[0]); } (function(){ var add = id('add'), list = id('list'), p = list.getElementsByTagName('p'), pLen = p.length, newLen = 0, newP = null, span; add.onclick = function(){ newLen = list.getElementsByTagName('p').length + 1; span = '<span>' + newLen + '</span><ins>delete</ins>'; newP = document.createElement('p'); newP.innerHTML = span; newP.onclick = function(e){ del(this, e); } list.appendChild(newP); } // del function del(node, e){ e = e || window.event; var target = e.target || e.currentTarget, span = list.getElementsByTagName('span'); if(target.tagName.toLowerCase() == 'ins'){ node.parentNode.removeChild(node); // reset span number for(var i = 0; i < list.getElementsByTagName('p').length; i++){ span[i].innerHTML = i + 1; } } } // old del for(var i = 0; i < pLen; i++){ p[i].onclick = function(e){ del(this, e); } } }()); </script>
运行代码
查看全文
相关阅读:
de1ctf_2019_weapon
ciscn_2019_s_6
用 Blend 给Windows Phone 应用创建 示例数据
(转) Wp7 list 中列表项多样化的解决方案-Custom DataTemplateSelector
Android开发之Java集合类性能分析
WriteableBitmap 给透明的控件截图的问题
VS 2013 配置OpenCV
Cocos2d-x 版本小游戏 《是男人就下100层》 项目开源
HEAP CORRUPTION DETECTED :after Normal block 错误
Visual C++ 的代码折叠
原文地址:https://www.cnblogs.com/jikey/p/2950900.html
最新文章
C++ 顺序表 代码实现
关于VC++6.0 MFC项目运行所需的动态链接库
《linux 鸟哥私房菜》
《深入理解计算机系统》
C语言一些需要注意的点
vim 命令理解记忆
pwn 环境搭建(wsl/vmware)
2020_gyctf_新春公益_pwn_复现
0ctf_babystack_ret2dl_resolve
静态链接 + mprotect
热门文章
hyper ls等命令报段错误
2020_强网杯_pwn_复现
七夕_DASCTF_pwn_复现
vsyscall bypass pie
ciscn_2020_pwn 复现
house of orange 源码分析
Brainfuck
ciscn_final_4(ptrace 堆沙箱绕过与 openat)
ciscn_2019_s_1
hitcon_2018_children_tcache
Copyright © 2011-2022 走看看