gpt4 book ai didi

javascript - 无法在页面中获取此 fiddle

转载 作者:行者123 更新时间:2023-11-28 05:47:00 28 4
gpt4 key购买 nike

我正在尝试制作this fiddle在网页上工作但没有成功。我以前做过这个,但是这个 fiddle 不起作用。

我尝试添加google的jquery或min jquery,但没有成功。我还尝试在 div 之后而不是在 header 中添加 javascript 代码,仍然没有成功。

有人可以帮忙吗?

下面是我的 html 代码......

<head>
<title>Untitled Document</title>
<script>
$(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>

<style type="text/css">
* { font-family:Arial; }
h2 { padding:0 0 5px 5px; }
h2 a { color: #224f99; }
a { color:#999; text-decoration: none; }
a:hover { color:#802727; }
p { padding:0 0 5px 0; }

input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
</style>

</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>


</form>
</body>

最佳答案

根据您提供的 html,几乎没有问题。

1:Jquery 未包含在您的 HTML 中。

2:直播功能已过时。如果您在网页中包含了 Jquery 1.9 或更高版本,但在问题中没有提到,那么您应该对动态附加元素使用事件委托(delegate)。

.on(eventType, selector, function)

尝试如下所示,它应该可以工作。

<html>
<head>
<title>Untitled Document</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;

$(document).on('click','#addScnt', 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;
});

$(document).on('click','#remScnt', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
</script>

<style type="text/css">
* { font-family:Arial; }
h2 { padding:0 0 5px 5px; }
h2 a { color: #224f99; }
a { color:#999; text-decoration: none; }
a:hover { color:#802727; }
p { padding:0 0 5px 0; }

input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
</style>

</head>

<body>
<form>
<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>


</form>
</body>
</html>

关于javascript - 无法在页面中获取此 fiddle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38428819/

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