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 日を選択すると、この 2 日間の間のすべての日/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 に答える