2014-03-28 151 views
1

我正在關注http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm?%28arctic%29#demos/jqxgrid/checkboxcolumn.htm 我想要做的是我試圖捕獲複選框上的變化迄今爲止我已經完成了類似這樣的事情,但以下不觸發任何事情可以告訴我我在這裏失蹤不能觸發Alert();在Jqxgrid複選框

jQuery('#jqxgrid').find('span').on("click",function() { 
        alert('i am here'); 
       }); 

jQuery('#jqxgrid').on("click",function() { 
         alert('This works but when i try to click on <span> that holds checkbox, it dont alert any thing other then this it works'); 
        }); 

和我的HTML簡直是如下

<body class='default'> 
     <div id="jqxgrid"></div> 
    </body> 

回答

1

嘗試使用event delegation,如果你的元素被動態地添加:

$('body').on('click', '#jqxgrid span', function() { 
    alert('i am here'); 
}); 

按照評論,你可以使用.find()

jQuery('#jqxgrid').on("click", function() {     
    var span = jQuery(this).find('.jqx-checkbox-check-checked'); 
}); 
+0

沒有觸發可言的,是創建活動動態 –

+0

請試試我的更新的代碼。 – Felix

+0

好吧,讓我檢查PLZ –