多种动态选择

发布于 2024-09-08 19:06:39 字数 90 浏览 1 评论 0原文

我需要一种有多个选择但一次只能看到一个的方法。 当用户想要添加另一个选择时,他/她单击按钮、复选框、单选按钮……等等 他们需要能够添加无限数量的选择。有什么想法吗?

I need a way of having multiple selections but only one visible at a time.
When the user wants to add another selection he/she clicks a button,checkbox,radio..whatever
They need to be able to add an unlimited number of selections. Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗化ㄋ丶相逢 2024-09-15 19:06:39

老问题,但不妨加上我的 2 美分,以防其他人想知道答案。

我将使用 JavaScript 在 JavaScript 循环的“更多”部分中创建一个

<input type="button" value="New Select Box" onclick="createNewBox();" /><br />
<span id="selectElement1">
    <select>[your code for the select box goes here]</select>
    <span id="selectElement2"></span>
</span>

Which 可以设置您的基本选择元素,并且 New Select Box 将激活此 JavaScript 函数代码:

<script type="text/javascript">
// Initialization Code
var currentSelect = 1; // Keeps track of which select box is current

// New Select Box code
function createNewBox()
{
    var currentSelect = currentSelect + 1;
    var nextSelect = currentSelect + 1;
    document.getElementById('selectElement'+currentSelect).innerHTML = "<select>[code goes here]</select><span id=\"selectElement"+nextSelect+"\"></span>";
}
</script>

这整个事情可以仅使用这两个代码片段运行,而无需 jQuery需要代码。

Old question, but might as well add my 2 cents, in case anyone else wants to know an answer.

I would use JavaScript to create a <select> element in a "more" section, from a JavaScript loop. For example, your first page would have

<input type="button" value="New Select Box" onclick="createNewBox();" /><br />
<span id="selectElement1">
    <select>[your code for the select box goes here]</select>
    <span id="selectElement2"></span>
</span>

Which could setup your basic select element, and the New Select Box would activate this JavaScript function code:

<script type="text/javascript">
// Initialization Code
var currentSelect = 1; // Keeps track of which select box is current

// New Select Box code
function createNewBox()
{
    var currentSelect = currentSelect + 1;
    var nextSelect = currentSelect + 1;
    document.getElementById('selectElement'+currentSelect).innerHTML = "<select>[code goes here]</select><span id=\"selectElement"+nextSelect+"\"></span>";
}
</script>

This whole thing can run with only those two code snippets, and no jQuery code is needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文