2013-01-21 58 views

回答

0

你可以使用jQuery點擊事件綁定單擊元素。 Here is an example of the same.以下是綁定的總體佈局。

 $('.layout_block').click(function() { 
       //function to set some properties using $(this) 
       //setting an identifier to remove the element 
     } 

這裏layout_block是gridster所有元素的類。

+0

這對初始化後添加的元素不起作用。我嘗試使用'$('。layout_block')。on('click',function(){});',但這也不起作用。 –

+0

任何你使用的方法,新的元素將不得不註冊他們的事件處理程序,這涉及到重新初始化.click()函數。 – Nupur

+1

啊,當然!現在它的作品:'var widget = gridster.add_widget('

  • foo
  • ',size_x,size_y); widget.click(myFunction的);'。謝謝。 –

    0

    javascript $(document).on("click", ".layout_block", handler);

    工作對我來說,甚至對於那些加入gridster.add_widget();部件。

    0

    我有這個工作代碼。

    $(".gridster ul li button.close").click(function() { 
         gridster.remove_widget($(this).parent()); 
    }); 
    

    所以在我的鋰元素,我對檢測單擊事件與class=close一個按鈕,我稱之爲小部件方法gridster.remove_widget,並通過它來刪除HTML元素。

    快樂編碼:)