0

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

有谁知道如何手动或以编程方式选择可选择的 jQuery UI 的子项?

4

2 回答 2

2

这不是可选对象独有的,但如果您只想获取 html 节点,可以使用此处:nth-child()找到的选择器。

$(".selector li:nth-child(2)")

根据您需要对这个孩子做什么,这可能对您有用。

编辑

我想我错过了您对“选择”的预期含义。我没有立即看到使用 API 选择项目的简单方法,但您始终可以将类添加ui-selected到子项目中,其余的应该由 css 处理。但是,这可能不会触发 API 事件。

或者,你可以这样做

$(".selector li:nth-child(2)").click();

用假鼠标点击选择。

于 2012-11-11T00:35:03.530 回答
0

从我对这个问题的回答...

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);
}
于 2012-12-19T16:59:56.510 回答