我生成的下拉菜单适用于 Firefox 和 IE,但不适用于 Google Chrome。我有
function characterList(){
//code removed that generates select list
var optionContainer = document.createElement("option");
optionContainer.innerHTML = "Show All Character Lines";
addEvent(optionContainer, "click", filterChar, false);
selectContainer.appendChild(optionContainer); //appends option to select menu
for (var i = 0; i < menu_lines; i++){
var optionContainer1 = document.createElement("option");
optionContainer1.innerHTML = "blah" //simplified so that names in menu are all "blah"
selectContainer.appendChild(optionContainer1);//appends option to select menu
addEvent(optionContainer1, "click", filterChar, false);//I think the problem is here.
}
}
function filterChar(){
alert("filterChar");
}
function addEvent(object, evName, fnName, cap) {
if (object.attachEvent)
object.attachEvent("on" + evName, fnName);
else if (object.addEventListener)
object.addEventListener(evName, fnName, cap);
}
characterList 使用取自 HTML 文件的 h3 标题的名称填充下拉菜单(选择选项类型)。这工作正常。问题是在谷歌浏览器中,点击下拉菜单时不会调用 filterChar。我有一个应该与所有浏览器兼容的函数(attachEvent)。请有人帮忙。