我有一个PHP文件中的这行代码:
echo "<input type='button' id='showButton' value='show' onclick='showOld()'>";
该函数位于外部JS文件中。 函数声明如下:
页面中的其他onclick
事件和JS函数都能够正常工作。
function showOld()
{
alert("njkh");
var table = document.getElementById("showExp");
var button = document.getElementById("showButton");
if (table.style.display == "none")
{
table.style.display = "inline";
button.value = "הסתר ניסויים ישנים";
}
else if (table.style.display == "inline")
{
table.style.display = "none";
button.value = "הצג את כל הניסויים";
}
}
控制台显示:
"引用错误:showOld未定义"
showOld()
。 - Shef