2011-09-22 3 views
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'요소를 선택하고 싶지만 모두 선택합니다. 몇 가지 시도를했지만 효과가 없습니다.jquery 선택 가능한 첫 번째 레벨 하위 항목을 선택하는 플러그인

+0

당신이있어 무엇의 예에 링크 할 수 여기에 솔루션

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

것이 사용자 정의 플러그인

$.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 } }); 

을 추가 할 수 있습니다 달성하려고? 여러분의 질문에 관심이있는 모든 사람들이 jQuery-ui-selectable이 무엇인지 알지 못합니다. –

+0

(별도 문제) JS에 HTML을 제공하지 않았습니다. 거기에 어떤 것이 있습니까? –

답변

1

<li> 요소를 선택하면 <li>을 클릭하면 해당 요소의 내용도 '선택'됩니다.

jQuery UI에 관한 한, 실제로는 <li> 만 '선택됨'입니다. 선택한 경우 <li>ui-selected 클래스가 주어짐에 따라이를 볼 수 있습니다. 반대로 내용은 ui-selectee 클래스로 주어집니다.

관련 문제