当前位置:网站首页>15 Uncaught TypeError: Cannot set properties of null (setting ‘onclick‘)
15 Uncaught TypeError: Cannot set properties of null (setting ‘onclick‘)
2022-06-09 13:56:00 【I want to walk the whole stack】
1、 Error code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> title </title>
<style type="text/css"> </style>
<script type="text/javascript"> // obtain button object var btn = document.getElementById("btn"); // Bind a handler to the corresponding event of the button to respond to the event , When the event is triggered , The corresponding function will be called btn.onclick = function () {
alert(" Triggered a click event "); }; var btn1 = document.getElementById("btn1"); var btn2 = document.getElementById("btn2"); btn1.onclick = function () {
document.getElementById("t2").value = document.getElementById("t1").value }; btn2.onclick = function () {
document.getElementById("t2").value = "" } </script>
</head>
<body>
<button id="btn"> I'm the button </button>
<br><br>
<input id="t1" type="text" value=" Text 1">
<input id="t2" type="text">
<button id="btn1">copy</button>
<button id="btn2"> Cancel </button>
</body>
</html>
2: Reasons for reporting errors
The loading process of the document is from top to bottom . Use unnamed variables 、 Will report a mistake
3、 terms of settlement
1、 take Javascript Code from <head> Put... In the label <body> in
2、 If you have to put this code into head What to do in the label ???

The modified code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> title </title>
<style type="text/css"> </style>
<script type="text/javascript"> window.onload = function(){
// obtain button object var btn = document.getElementById("btn"); // Bind a handler to the corresponding event of the button to respond to the event , When the event is triggered , The corresponding function will be called btn.onclick = function () {
alert(" Triggered a click event "); }; var btn1 = document.getElementById("btn1"); var btn2 = document.getElementById("btn2"); btn1.onclick = function () {
document.getElementById("t2").value = document.getElementById("t1").value }; btn2.onclick = function () {
document.getElementById("t2").value = "" } } </script>
</head>
<body>
<button id="btn"> I'm the button </button>
<br><br>
<input id="t1" type="text" value=" Text 1">
<input id="t2" type="text">
<button id="btn1">copy</button>
<button id="btn2"> Cancel </button>
</body>
</html>
边栏推荐
- [leetcode weekly race record] record of the 294th weekly race
- 2022.6.5-----leetcode.478
- Win11 enable multi-user remote desktop simultaneous login
- 6000 + words to help you understand the evolution of Internet architecture!
- Dr. Stanford put forward the idea of ultra fast and saving memory attention. The gpt-2 training speed was increased by 3.5 times, and the Bert speed reached a record
- [leetcode weekly race record] record of the 79th biweekly race + the 295th weekly race
- 论文阅读《LEAStereo:Hierarchical Neural Architecture Search for Deep Stereo Matching》
- 字节序,object类
- Best practices and principles of lean product development system
- 微信小程序
猜你喜欢

Yuna | the importance of server monitoring and the role of monitoring management server
详解mysql数据去重的三种方式

TCP(滑动窗口,流量控制)

栈的基本方法及相关问题

【数据库】期末复习:SQL语句、范式的定义和判断、ER图转关系模式

leetcode:497. 非重叠矩形中的随机点【随缘随机 + 前缀和二分 + 过了就行】

CNN's performance is even stronger without looking at the whole picture and the parts

面试题 05.06. 整数转换

【深度优先搜索】玩具蛇:迷宫问题
What is the difference between delete, drop and truncate in MySQL
随机推荐
Hype plagiarism, insider fraud common NFT scams and security suggestions on opensea
浅谈RedisTemplate和StringRedisTemplate的区别
Lossy transmission instance
2022.6.2-----leetcode.450
Hit the snake seven inches
左右最值最大差
微信小程序
CSDN音视频技术开发者在线调研
网络七层结构是干啥的?看这篇文章就够了
线程池创建方式详解
从最优化的角度看待Softmax损失函数
2022.6.7-----leetcode.875
CNN's performance is even stronger without looking at the whole picture and the parts
手把手教你用js实现一个虚拟机
The curl post request carries the request header and passes the command to receive parameter data
面试题 05.04. 下一个数
2022.5.29-----leetcode.468
HCIA datacom experiment IPv4 addressing and IPv4 routing basic experiment
selenium--显示等待(上)
What is the difference between delete, drop and truncate in MySQL