我正在尝试使用jquery选择器和对象数组。 这是一个例子..
//Declaration
var filterItems = Array();
filterItems[0] = { clickDiv: "CategoryPanelHeader", div: "NarrowByCategoryPanelWrapper" };
filterItems[1] = { clickDiv: "ExpandYourResultsHeader", div: "ExpandResultPanelWrapper" };
filterItems[2] = { clickDiv: "Keyword", div: "KeywordDiv" };
filterItems[3] = { clickDiv: "Manufacturer", div: "NarrowByManufacturerPanelWrapper" };
filterItems[4] = { clickDiv: "Credentials", div: "CredentialsDiv" };
和选择器
$(document).ready(function () {
//binds the click events...
for (var i = 0; i < filterItems.length; i++) {
$('#'+ filterItems[i].clickDiv).live('click', function () {
togglemenu($('#' + filterItems[i].div));
});
}
});
我可以在发出警报时正确读取每个项目,但jquery不会对点击事件进行约束。
我如何使用数组绑定onclick事件?
答案 0 :(得分:0)
$(document).ready(function () {
// gets all the click parameters...
for (var i = 0; i < filterItems.length; i++) {
bindClicks(($('#' + filterItems[i].clickDiv)), ($('#' + filterItems[i].div)) );
}
});
function bindClicks(clickdiv, expanddiv) {
//binds the click events
clickdiv.click(function () {
togglemenu(expanddiv);
});
}