我多次调用onclick
函数时遇到问题。问题是我使用的是相同的 ID,但我希望能够在第二次调用中再次重用该函数。这是我到目前为止所拥有的:
<p onclick='myfunction()'> Click this text for input box below </p>
<b id='myThing'>input box appears .. ta daa</b>
<p onclick='myfunction()'> Click this new text for input box below </p>
<div id='myThing'> but no input box appears here, the line above must turn this text into a textbox, but it doesn't because of similar id, how do i fix the id problem without defining a new id over and over?</div>
<script>
function myfunction(){
document.getElementById("myThing").innerHTML='<input type="text"/>';
}
</script>
有没有办法将 ID 转换为 Javascript 变量?如何使零件创建输入框?