gpt4 book ai didi

JQuery - 添加超过 1 个附件

转载 作者:太空宇宙 更新时间:2023-11-03 18:01:00 24 4
gpt4 key购买 nike

我想创建一个名为“添加新附件”的按钮和 5 个附件字段集。每次单击此按钮时,都会出现一个附件字段集,如果我再次单击此按钮,则会出现另一个附件字段集,依此类推。

单击按钮时,我的代码现在立即显示 5 个附件字段集!我怎样才能让这个 Action 起作用?请伸出援手。 Live Code非常感谢!

HTML

<button type="button" id="AddButtn">Add New Attach</button>
<p>
<div id="mainAttach" class="uploadCover">
<input id="attach1">Attach 1</input><br />
<input id="attach2">Attach 2</input><br />
<input id="attach3">Attach 3</input><br />
<input id="attach4">Attach 4</input><br />
<input id="attach5">Attach 5</input>
</div>
</p>

JS

$(document).ready(
function()
{
$('#AddButtn').click(
function()
{
$('#mainAttach').removeClass('uploadCover');
}
);
});

CSS

.uploadCover{
display:none;
}

最佳答案

您可以隐藏输入,然后像这样递增索引:

$(document).ready(function () {
$('input').hide();
var index = 0;
$('#AddButtn').click(function () {
index += 1;
$('#mainAttach').removeClass('uploadCover');
$('#attach' + index).show();
});
});

Working demo click here

关于JQuery - 添加超过 1 个附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25477695/

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