如何使用jQuery UI以编程方式选择可选项?

前端之家收集整理的这篇文章主要介绍了如何使用jQuery UI以编程方式选择可选项?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一系列可选项目。我想在其中添加一个按钮,激活其中的预设选项。有办法可以做到吗?

我想要的是告诉它“选择这些家伙”,然后让所有的事件都被正常触发,所以我不必手动调用所有这些选择事件。

更多信息:我谈到的事件是their apitheir demo page中列出的事件:

>选择
>选择
>开始
>停止
>未选择
>取消选择

而且,我认为在选择时可能会设置/清除数据。所以不仅仅是添加这些css类。

解决方法

以下是使用多个元素的Alex R代码的变体

http://jsfiddle.net/XYJEN/1/

function SelectSelectableElements (selectableContainer,elementsToSelect)
{
    // add unselecting class to all elements in the styleboard canvas except the ones to select
    $(".ui-selected",selectableContainer).not(elementsToSelect).removeClass("ui-selected").addClass("ui-unselecting");

    // add ui-selecting class to the elements to select
    $(elementsToSelect).not(".ui-selected").addClass("ui-selecting");

    // trigger the mouse stop event (this will select all .ui-selecting elements,and deselect all .ui-unselecting elements)
    selectableContainer.data("selectable")._mouseStop(null);
}

更新:

jQueryUI 1.10,来自kmk:http://jsfiddle.net/XYJEN/163/评论

原文链接:https://www.f2er.com/jquery/183355.html

猜你在找的jQuery相关文章