<script type="text/javascript">
window.onload = function () {
document.getElementById("btn").onclick = function () {
alert(document.getElementById("text").value);
}
}
</script>
<input type="text" id="text">
<input type="button" id="btn" value="获取文本框中的内容">
<script type="text/javascript">
window.onload = function () {
document.getElementById("setbtn").onclick = function () {
document.getElementById("username2").value = document.getElementById("username1").value
}
}
</script>
<input type="text" id="username1">
<br>
<input type="text" id="username2">
<br>
<input type="button" value="将第一个文本框上的值复制到第二个文本框上" id="setbtn">
<br>
<input type="text" onblur="alert(this.value+'失去焦点')">
```c++
```
同一个页面只能存在一个 window.onload = function(){}
有用望采纳
把脚本和html的位置互换一下
最好 js放在 body下面 。要不然 就会出现这种问题。