【发布时间】:2017-04-01 05:36:32
【问题描述】:
我想要一个包含链接的div。点击时,链接应该被<input type="text">替换,但是它不起作用。
任何其他 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>
【问题讨论】:
-
请在问题中包含所有代码
-
您的拼写错误导致语法错误。当某些东西“不起作用”时,您应该至少查看调试控制台是否有任何错误。
标签: javascript html