[英]How to get/set input fields from multiple html from same external JavaScript file?
I have two html files, A.html and B.html, and one external java script file called C.js When I run A.html, I want to read value of input filed of B.html from Java script but it's not reading value of input field. 我有两个html文件A.html和B.html,以及一个名为C.js的外部Java脚本文件。当我运行A.html时,我想从Java脚本中读取B.html的输入文件的值,但它没有读取输入字段的值。 It just returns null.
它只是返回null。 B.html looks like this (I am showing only form)
B.html看起来像这样(我仅显示表格)
<form action="" name="form1" id="form1">
<input type="text" name="text1" id="text1" value="Hello">
</form>
I have this code in Java script (C.js) which is called by A.html successfully. 我在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.
}
Did I miss anything that prevented Java script code from reading the text value from A.html? 我是否错过了阻止Java脚本代码从A.html读取文本值的任何内容?
尝试将“ .value”更改为“ .innerHTML”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.