A.html と B.html の 2 つの html ファイルと、C.js という 1 つの外部 Java スクリプト ファイルがあります。A.html を実行すると、Java スクリプトから B.html の入力フィールドの値を読み取りたいのですが、読み取れません。入力フィールドの値。null を返すだけです。B.html は次のようになります (フォームのみを表示しています)
<form action="" name="form1" id="form1">
<input type="text" name="text1" id="text1" value="Hello">
</form>
A.htmlによって正常に呼び出されるJavaスクリプト(C.js)にこのコードがあります。
function readInputText(){
var myVal = document.getElementById("text1").value;
// Above line is not working. I tried document.form1.text1.value also but did not work.
}
Java スクリプト コードが A.html からテキスト値を読み取るのを妨げていたものを見落としていませんか?