我想擁有一個包含鏈接的div
。點擊時,鏈接應該被替換爲<input type="text">
,但它不起作用。如何在使用javascript單擊HTML鏈接時添加輸入表單?
其他HTML代碼的工作,但由於某種原因,我不能沒有與輸入鏈接:
function working() {
document.getElementById("working").innerHTML = "<h1>Test</h1>";
};
function notworking() {
document.getElementById("notworking").innerHTML = "<input type="text">";
};
<div id="working">
<a onclick="working();" href="#">This works!</a>
</div>
<div id="notworking">
<a onclick="notworking();" href="#">This doesn't!</a>
</div>
<p>
Notice that the entire code doesn't work unless you comment out the "notworking()" function!
</p>
報價請在問題的所有代碼 – Liam
你有導致語法錯誤錯字。當某些「不工作」時,您至少應*查看調試控制檯是否有任何錯誤。 – David