请老师帮忙检查一下代码,谢谢
来源:2-13 编程练习
廖可爱bongbong
2021-06-08 19:52:51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Location 对象</title>
<style>
div {
text-align: center;
position: relative;
margin-top: 300px;
}
</style>
</head>
<body>
<!-- 补充代码 -->
<div>
<span>用户名:</span>
<input type="text" id="name_input">
<br>
<br>
<span>密 码:</span>
<input type="password" id="password_input">
<br>
<br>
<button id="btn">提交</button>
</div>
<script>
//获取元素
var nameInput = document.getElementById('name_input');
var passwordInput = document.getElementById('password_input');
var btn = document.getElementById('btn');
btn.onclick = function () {
if (nameInput.value == '张三' && passwordInput.value == '123456') {
window.location = 'https://www.imooc.com';
} else {
alert('信息不对');
}
}
</script>
</body>
</html>
1回答
同学你好,代码正确,很棒!!!祝学习愉快~
相似问题