jquery click事件 添加html标签后 再次点击无反应
想做一个追加input框的功能,代码如下
html代码:
<div class='xhdz'><input type='text' name='xhmc[]' style='width:100px;margin-right:10px;' value='' /><input type='text' name='xhdz[]' class='intxt' value='' /><a href='javascript:void(0)' id='addone'>添加一条</a></div>
js代码:
$(document).ready(function(){
$('#addone').on('click', function(){
var str = "<div class='xhdz'><input type='text' name='xhmc[]' style='width:100px;margin-right:10px;' value='' /><input type='text' name='xhdz[]' class='intxt' value='' /><a href='javascript:void(0)' id='addone'>添加一条</a><a href='javascript:void(0)' class='delone''>删除</a></div>";
$(this).parent().after(str);
$('.delone').click(function(){
$(this).parent().remove();
});
});
});
点击html代码部分的“添加一条”可以添加,但是jquery追加的部分再次点击“添加一条” 就没办法添加了,求大神指点
html代码:
<div class='xhdz'><input type='text' name='xhmc[]' style='width:100px;margin-right:10px;' value='' /><input type='text' name='xhdz[]' class='intxt' value='' /><a href='javascript:void(0)' id='addone'>添加一条</a></div>
js代码:
$(document).ready(function(){
$('#addone').on('click', function(){
var str = "<div class='xhdz'><input type='text' name='xhmc[]' style='width:100px;margin-right:10px;' value='' /><input type='text' name='xhdz[]' class='intxt' value='' /><a href='javascript:void(0)' id='addone'>添加一条</a><a href='javascript:void(0)' class='delone''>删除</a></div>";
$(this).parent().after(str);
$('.delone').click(function(){
$(this).parent().remove();
});
});
});
点击html代码部分的“添加一条”可以添加,但是jquery追加的部分再次点击“添加一条” 就没办法添加了,求大神指点
...全文
相关推荐
jquery A标签onclick事件
#### 一、jQuery 与 onclick 事件在 jQuery 中,可以使用 `.click()` 方法轻松地为元素绑定点击事件。当用户点击该元素时,绑定的函数就会被触发。
jquery 为a标签绑定click事件示例代码
在给定的标题和描述中,我们看到如何使用 jQuery 为 HTML 中的 `<a>`(超链接)标签绑定 `click` 事件。下面将详细讲解这个过程,以及涉及到的相关知识点。
jquery单选框radio绑定click事件实现方法
本文将深入讲解如何使用jQuery来绑定单选框(radio)的click事件,以便在用户点击时执行特定的功能。首先,jQuery的选择器是其强大功能的核心。
html5 svg 中元素点击事件添加方法
在移动设备,特别是iPad上,可能需要确保SVG元素的点击事件正确地添加。有时候直接使用jQuery等库添加事件可能不会在所有设备上生效。
JQuery调用绑定click事件的3种写法
"); });});```这段代码会在页面加载完毕后,为ID为`clickme`的按钮添加一个点击事件,当用户点击这个按钮时,会弹出警告框显示“Hello World click”。


