gpt4 book ai didi

javascript - 使用 jquery 添加和删除 div 不起作用

转载 作者:行者123 更新时间:2023-12-03 12:24:11 25 4
gpt4 key购买 nike

我正在使用一个简单的脚本来使用 jquery 添加和删除 div。但这不起作用。是否需要包含任何文件?谁能帮我。

这是我的代码

<html>    
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript">
$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;

$('#addScnt').live('click', function() {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20"

name="p_scnt_' + i +'" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
</script>
</head>
<body>
<h2><a href="#" id="addScnt">Add Another Input Box</a></h2>
<div id="p_scents">
<p>
<label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt" value="" placeholder="Input Value" /></label>
</p>
</div>
</body>
</html>

最佳答案

.live() 从 jquery 1.7 开始已弃用。在 jquery 中使用 .on() 代替 .live()

关于javascript - 使用 jquery 添加和删除 div 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com