onclick
関数を複数回呼び出すことに問題があります。問題は、同じ ID を使用していることですが、2 回目の呼び出しで関数を再利用できるようにしたいということです。これが私がこれまでに持っているものです:
<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 変数に変換する方法はありますか? パーツに入力ボックスを作成させるにはどうすればよいですか?