ボタンがクリックされたときに呼び出される関数 openWindow(word) があります。この関数は、新しいウィンドウを開き、単語を出力し、do というボタンを表示します。openWindow 関数は、そのタグの onclick が do 関数を見つけることになるまで機能します。私の問題は、onclick が do 関数を見つけられないように見えることです。私は何をしますか?
私の機能:
function do() {
alert("Life is what you make of it");
}
私のopenWindow関数:
function openWindow(word) {
myWindow.document.write(word);
myWindow.document.write('<body>');
myWindow.document.write('<input type="button" value="Do" onclick="do()">');
myWindow.document.write('</body>');
}
}
ウィンドウを開くための私のhtmlコード:
<body>
<input type="button" value="Submit" onclick="openWindow()">
</body>