扫码关注官方订阅号
for(var i=0;.......){ $("#groupUser").prepend("" +"姓名:xxxx 邮箱:xxxx 角色:xxxx" +" +" +"" +"管理员 " +" +""); }
管理员
当点击函数触发后想要往class='modifyForm'这个p中添加元素,但是只在被点击的那个中添加而不是for循环中的所有;
认证高级PHP讲师
$(this).parent() #获取父元素 $('.modifyForm').append(dom) #在末尾添加元素
function modifyUser(e) { var childText = document.createTextNode('hello'); var child = document.createElement('p'); var parent = e.srcElement.parentElement; child.appendChild(childText); parent.lastElementChild.appendChild(child) }
$('#groupUser').on('click','.fa-edit',function(){ //绑定事件
$(this).parent(); //获取父元素
})
这样试试
更省事点的话你直接把事件绑外层就是了。。。反正click会冒泡
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
$('#groupUser').on('click','.fa-edit',function(){ //绑定事件
})
这样试试
更省事点的话你直接把事件绑外层就是了。。。反正click会冒泡