jQuery:如何在单个页面上多次使用相同的小部件
jQuery UI 似乎对组成小部件的元素的属性很敏感。那么如何在单个页面\表单中多次使用相同的小部件?
示例 - 单选选择小部件,它位于使用 jQuery-ui 下载的演示 index.html 文件中:
<!DOCTYPE html>
<html>
<head>
...
$(function(){
$("#radioset").buttonset();
}
...
</head>
<body>
...
<form style="margin-top: 1em;">
<div id="radioset">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
</form>
...
</body>
</html>
那么我应该添加什么代码才能拥有带有一组不同单选按钮的第二个 div?
jQuery UI seems to be sensitive to the attributes of the elements that compose a widget. How then can I use the same widget mutiple times in a single page\form?
Example - the radio select widget, which comes in the demo index.html file that downloads with jQuery-ui:
<!DOCTYPE html>
<html>
<head>
...
$(function(){
$("#radioset").buttonset();
}
...
</head>
<body>
...
<form style="margin-top: 1em;">
<div id="radioset">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
</form>
...
</body>
</html>
What code then should I add to have a second div with a different set of radio buttons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它实际上并不需要将表格包裹起来。相反,您只需确保您的无线电组具有不同的名称即可。 此处有更详细的解释。
It doesn't actually require the form to be wrapped around. Instead, you just need to make sure your radio groups have different names. It's explained in greater detail here .
我相信这就是您想要的,以及如何将 2 个不同的无线电装置放入一种形式的示例。注意输入的名称
I believe this is what you want, along with an example of how to put 2 different radio sets into one form. Notice the NAME of the inputs
或者你可以使用
Wich 选择无线电集类而不是 id,这样你就可以有很多。
针对您的评论:
我认为上述内容没有理由不起作用。
Or you could use
Wich would select the radioset class not the id so you could have many.
To address your comment:
I see no reason for the above not to work.