[英]jQuery UI: How can I have more than one "selectable" element if the element has to have id="selectable"?
All of the demo's ive been able to find follow this pattern:我能找到的所有演示都遵循这种模式:
<ol id="selectable">
<li class="ui-widget-content">Item 1</li>
<li class="ui-widget-content">Item 2</li>
..
</ol>
jQuery UI selectable demo jQuery UI可选演示
I've tried changing the ID of the list to something unique but it doesn't seem to work.我试过将列表的 ID 更改为唯一的 ID,但它似乎不起作用。 Is it a requirement that the selectable element have and id of "selectable" and if so, how can you make more than one list selectable?是否要求可选元素具有“可选择”的 ID,如果是这样,您如何使多个列表可选择?
It is not a requirement to use an id.不需要使用 id。 In fact, you aren't required to use html lists either.事实上,您也不需要使用 html 列表。
The following example uses a <div>
as the container and <span>
elements as the selectable items.以下示例使用<div>
作为容器,使用<span>
元素作为可选项目。
<div class="group">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
</div>
<script>
$(".group").selectable({ filter: 'span' });
</script>
The next example uses a data attribute selector [data-album]
to target multiple containers.下一个示例使用数据属性选择器[data-album]
来定位多个容器。 Each of these <p>
elements will be converted into a separate selectable with their child <img>
elements as selectees.这些<p>
元素中的每一个都将被转换为一个单独的可选择项,并将它们的子<img>
元素作为被选中者。
<p data-album="Vacation">
<img src="..." />
<img src="..." />
<img src="..." />
</p>
<p data-album="Birthdays">
<img src="..." />
<img src="..." />
<img src="..." />
</p>
<script>
$("[data-album]").selectable({ filter: 'img' });
</script>
The operational code is:运行代码为:
$(function() {
$( "#selectable" ).selectable();
});
You can replace #selectable
with any selector that points to what you want to make selectable.您可以将#selectable
替换为任何指向您想要选择的内容的选择器。 So it doesn't have to be an ID.所以它不一定是身份证。 It could be a class like .selectable
.它可能是 class 之类的.selectable
。
Use a class instead of an element.使用 class 而不是元素。 An element's class can contain multiple value.一个元素的 class 可以包含多个值。
Just change te line只需更改 te 行
¥('selectable').selectable();
To到
¥('idChosed').selectable();
For each element you choosed对于您选择的每个元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.