Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
这个问题在这里已有答案:
我有两个问题。
1)我写了这个html标签,并在单独的文件中创建了javascript。<input type="text" id="callno" value="3333">
在js中,我有
var PhoneNumber = document.getElementById("callno").value;
但是,当我在浏览器(谷歌浏览器)中查看控制台时,我发现有一个错误未捕获的TypeError:无法读取null的属性'value' 。
2)每当我更新html标签的值时,如何自动更新PhoneNumber的值,我怎么能这样做。
This question already has an answer here:
I have two questions.
1) I wrote this html tag and created javascript in separate file.<input type="text" id="callno" value="3333">
In the js, I have
var PhoneNumber = document.getElementById("callno").value;
However, when I look at the console in the browser (Google Chrome) I saw that there is an error Uncaught TypeError: Cannot read property 'value' of null.
2) How can I make that each time when I update value of html tag in above the value of PhoneNumber updated automatically.
满意答案
这应该工作:
<!DOCTYPE html> <html> <body> <input id="myInput" onchange="myFunction()" value="1234"> <p>Change the above input value and click enter.</p> <p id="myOutput">VALUE HERE</p> <script> var x; function myFunction() { x = document.getElementById("myInput").value; document.getElementById("myOutput").innerHTML = x; } </script> </body> </html>
This should work:
<!DOCTYPE html> <html> <body> <input id="myInput" onchange="myFunction()" value="1234"> <p>Change the above input value and click enter.</p> <p id="myOutput">VALUE HERE</p> <script> var x; function myFunction() { x = document.getElementById("myInput").value; document.getElementById("myOutput").innerHTML = x; } </script> </body> </html>
相关问答
更多JAVASCRIPT - 未捕获的TypeError:无法读取null的属性“value”(JAVASCRIPT - Uncaught TypeError: Cannot read property 'value' of null)
未捕获的TypeError:在else语句中无法读取null的属性'style'(Uncaught TypeError: Cannot read property 'style' of null in else statement)
谷歌地图错误未捕获TypeError:无法读取null的属性'offsetWidth'(google maps error Uncaught TypeError: Cannot read property 'offsetWidth' of null)
未捕获的TypeError:无法读取null的属性'getContext'(Uncaught TypeError: Cannot read property 'getContext' of null)
Extjs5 Uncaught TypeError:无法读取null的属性'metaData'(Extjs5 Uncaught TypeError: Cannot read property 'metaData' of null)
未捕获的TypeError:无法使用数组读取null的属性“data”(Uncaught TypeError: Cannot read property 'data' of null using array)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
未捕获的TypeError:无法读取null的属性'documentElement'(Uncaught TypeError: Cannot read property 'documentElement' of null)
JavaScript:未捕获的TypeError:无法读取null的属性'style'[重复](JavaScript: Uncaught TypeError: Cannot read property 'style' of null [duplicate])
未捕获的TypeError:无法在React类中读取null的属性'props'[重复](Uncaught TypeError: Cannot read property 'props' of null in React Class [duplicate])
相关文章
更多命令行运行Hbase: Session 0x0 for server null, unexpected error
Hibernate创建sessionFactory null
could not find system property or JNDI
mybatis There is no getter for property named 'xx' in 'class java.lang.String
List用完后需要赋null吗
Failed to read auto-increment value from storage engine错误的解决方法
null 写“==”前和写“==”有何区别
Guava学习笔记:Optional优雅的使用null
jfreechart如何去掉为null的空白占位
Guava Optional类详解-处理null值
最新问答
更多绝地求生、荒野行动、香肠派对 哪个更好玩???(都是吃鸡类游戏)
如何在jQuery集合中选择第n个jQuery对象?(How to select the nth jQuery object in a jQuery collection?)
ASP NET使用jQuery和AJAX上传图像(ASP NET upload image with jQuery and AJAX)
SQL Server XML查询中包含名称空间的位置(SQL Server XML query with namespaces in the where exist)
宁夏银川永宁县望远镇哪里有修mp5的?
我想用更新的日期标记所有更新的行(I would like to mark all updated rows with the date that they have been updated)
郑州会计培训班
如何定位数组中的负数,并得到所有正数的总和?(How to target e negative number from an array, and get the sum of all positive numbers?)
在响应图像上叠加网格(Overlay grid on responsive image)
无法让POST在Azure网站上运行(Could not get POST to work on Azure Website)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!