这是实际代码,如何list[i].fnctn
正确传递给点击处理程序?
list[i].fnctn
- 包含我要附加到单击事件处理程序的函数的名称。
function createList(list){
var parentID = $("#content_nav ul");
var len = list.length;
for(var i=0;i<len;i++){
var anchorElement = jQuery('<a />',{text:list[i].text});
var liElement = jQuery('<li />',{"class":"navlink_"+(i+1),id:"navlink_"+(i+1)});
//anchorElement.attr('onclick',list[i].fnctn+"()"); - Works fine on desktop browsers but doesn't work on mobile devices. (Mobile devices are my target platform
anchorElement.on('click',function(event) {
return window[list[i].fnctn](event); // Here I am getting the error - cannot access property fnctn of undefined
});
liElement.append(anchorElement);
parentID.append(liElement);
}
}