是不確定我有,我想取決於複選框的「檢查」狀態採取一些行動的方法。該「點擊」事件工作正常,但在foreach循環的「myFunction的」打不:「這」在jQuery的自定義方法
$(document).ready(function(){
$('#TreeView1 :checkbox')
.click(HandleCheckbox); // Works fine
// Go through the entire Category treeview to
// see if there are any checkboxes that are already
// checked.
$.fn.myFunction = HandleCheckbox;
$(":checked:checkbox").each(function(index) {
// In the HandleCheckbox 'this' is undefined.
$(this).myFunction();
});
});
function HandleCheckbox() {
alert(this.name + '=' + this.checked);
}
在上面的代碼中,「點擊」方法火災時,‘本’的定義,如預期。當我在foreach循環中調用'muFunction'時,'HandleCheckbox'函數中未定義'this'。
我仍然在學習jQuery的繩索,因此,如果有這樣的「好」或更簡單的方法,請讓我知道。
謝謝。
這是我的情況最優雅的解決方案。謝謝。 – 2009-07-27 19:01:21