0
   <ol id="selectable">
    <li class="ui-widget-content">
           <div><input type="checkbox" /></div>
           <div>Item1</div>
           <div>Khanput</div>
           <div>1/2/3</div>
           <div>15:03:16</div>
           <div>--------</div>
           <div>23m</div>
           <div>Chakwal</div>
       </li>
   </ol>

「div」ではなく「li」要素を選択したいだけですが、それらすべてが選択されます。私はいくつかのことを試しましたが、うまくいきませんでした。

4

2 に答える 2

1

要素を選択可能にすると、クリックし<li>たときにその中のコンテンツも「選択」されるのは理にかなっています。<li>

ただし、jQuery UI に関する限り、<li>実際に「選択」されているのは のみです。これは、選択されたときに<li>クラスが与えられるので見ることができます。ui-selected逆に、その中のコンテンツにはui-selecteeクラスが与えられます。

于 2011-09-22T22:54:57.810 に答える
0

このカスタムプラグインを追加できます

$.widget("xim.singleSelectable", {
    options: {
        select: null
    },
    _create: function () {
        var self = this;
        this.element.addClass('ui-selectable');
        this.element.delegate('li', 'click', function (e) {
            self.element.find('>li').removeClass('ui-selected');
            $(this).addClass('ui-selected');

            if ($.isFunction(self.options.select)) {
                self.options.select.apply(self.element, [e, this]);
            }

        });
    },
    selected: function () {
        return this.element.find('li.ui-selected');
    },
    destroy: function () {
        $.Widget.prototype.destroy.apply(this, arguments); // default destroy
    }
});

あなたのコードは

$( "#selectable" ).selectable({         
            stop: function() {                
                $( "li.ui-selected", this ).each(function() {
                    var index = $( "#selectable li" ).index( this );                   
                    alert(index);                                       
                });                
            }                        
        });

ここで解決策を見つけました jQuery UI Selectable pluginで複数選択を防ぐ方法

于 2012-11-11T17:59:52.093 に答える