我有一個HTML菜單選項,這是我在jQuery的綁定一個click
處理程序:jQuery的綁定上下文匹配
var xyz = {
getMainContainerSelector: function() {
return '.container#main';
},
bindMenuOptions: function() {
$('#menu_outcome_list').bind('click', function() {
// inject template
$(this.getMainContainerSelector()).html(ich.outcomeListTemplate({}));
// load datatable
$('#outcomes').dataTable({
"bServerSide": true,
'sPaginationType': 'bootstrap',
"sAjaxSource": '../php/client/json.php?type=outcomes'
});
});
},
...
}
我有下面的行了一個問題:
$(this.getMainContainerSelector()).html(ich.outcomeListTemplate({}));
我想這是一個背景問題。我的意思是,在綁定函數中,this
不再是xyz
,而是('#menu_outcome_list')HTML元素。我想要做的只是從綁定函數中調用xyz
的方法。
確實xyz.getMainContainerSelector()不起作用? – 2013-04-04 19:51:36
注意,使用'.container#main'沒有什麼意義,只要使用'#main' – 2013-04-04 19:53:03
@KevinB,好吧,你是對的;) – ducin 2013-04-04 19:54:49