1

当在元素上使用选择时,我正在尝试获取选定的项目。这是html代码:

<div id="yearCal" class="ui-selectable">
    <div id="month_1" class="month">
        <div class="monthTitle">January</div>
        <div class="monthDays" id="month_1_days">
            <div class="monthDay ui-selectee" id="1-1">1</div>
            <div class="monthDay ui-selectee" id="1-2">2</div>
            ...
        </div>
        ...
    </div>
</div>

这就是 jQuery 代码:

$( "#yearCal" ).selectable({ filter: "div.monthDay" });
$( "#yearCal" ).on( "selectableselecting", function( event, ui ) {
    console.log($("div#yearCal.monthDay ui-selectee ui-selected"));
} );

如果我正在选择 的元素,如何获取选定的项目yearCal?我要做的是,如果我选择 1 月 1 日然后选择 2 月 1 日,我希望选择这两天之间的所有天/div 项目。因此,我想要所选项目的 ID。如何获得选定的项目?

4

1 回答 1

0

ui.selecting.id您可以使用函数内部selectableselecting和获取选定的内部项目selectableunselecting

文档:http ://api.jqueryui.com/selectable/#event-selecting和http://api.jqueryui.com/selectable/#event-unselecting

在这个片段中,我记录了选定的元素并设置了一个特定的类,但你可以做你所有的事情:

$("#yearCal").on("selectableselecting", function (event, ui) {
    console.log(ui.selecting.id);
    $('#' + ui.selecting.id).addClass('boxed');
});

$("#yearCal").on("selectableunselecting", function (event, ui) {
    console.log(ui.unselecting.id);
    $('#' + ui.unselecting.id).removeClass('boxed');
});

这是一个工作小提琴:http: //jsfiddle.net/IrvinDominin/shTpK/

于 2013-05-22T06:36:41.833 回答