我有以下JS代碼。當加載test.php時,我點擊按鈕顯示功能沒有被調用。我試圖在FF上。任何建議這裏有什麼不對。無法調用Javascript函數從按鈕onclick
test.php的
<script type="text/javascript" src="http://localhost/test1.js"></script>
<script type="text/javascript" src="http://localhost/test2.js"></script>
test1.js
function show()
{
alert("hello");
}
test2.js
function showHTML()
{
var html = "<!DOCTYPE html>";
html += "<html><body>";
html += "<input type='button' name='button' style='width:100px;height:50px;' onclick='show();' />";
html += "</body></html>";
document.write(html);
}
window.addEventListener("load", function() {
alert("eevnet");
showHTML();
}, false);
'document.write',當文檔初始渲染完成後調用__replaces__當前文檔。新文檔==您的腳本文件不再被嵌入。請不要再使用像'document.write'這樣的東西,而應該查看_Unobtrusive JavaScript_。 – CBroe
可以告訴我什麼是不顯眼的JavaScript – anand
@CBroe - 但它不會在問題中初始渲染後調用。 – Quentin