<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Blog-主页</title>
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/nav.css">
<link rel="stylesheet" href="./css/index.css">
<link rel="stylesheet" href="./css/dialog.css">
</head>
<body>
<header>
<nav>
<ul>
<li><img src="./imgs/book.png" alt="书籍图片-用作网页logo" srcset=""></li>
<li><a href="">主页</a></li>
<li><a href="">博文</a></li>
<li><a href="">我的</a></li>
</ul>
</nav>
<section>
<div>
<h1>Test</h1>
<p>
Test
</p>
</div>
</section>
</header>
<section class="register-now">
<div>
<h1>注册!</h1>
<p>Test</p>
<button class="user-dialog-button">注册</button>
</div>
</section>
<dialog class="user-dialog">
<form method="post" action="#">
<h2>注册</h2>
<label for="username">用户名</label>
<input type="text" name="username" id="" />
<br>
<label for="email">邮箱</label>
<input type="text" name="email" id="" />
<br>
<label for="user-password">密码</label>
<input type="password" name="user-password" id="">
<br>
<input type="checkbox" name="user-rules">
<label for="rules">我同意《用户协议》</label>
<br>
<button id="submit" onclick="return false;">注册</button>
</form>
<br>
<button id="change">切换登录</button>
<form method="dialog">
<button id="close-user-dialog">X 关闭</button>
</form>
</dialog>
<footer>
<h3>友情链接</h3>
<ul>
<li><a href="">Example</a></li>
</ul>
</footer>
<script src="./scripts/base.js"></script>
<script src="./scripts/user-dialog.js"></script>
</body>
</html>
import jquery from "./jquery";
document.querySelector(".user-dialog-button").addEventListener("click",function set_event() {;
let element = document.querySelector(".user-dialog");
element.showModal();
})
function send_data(){
let json_data = {"username":document.getElementsByName("username").innerText,
"password":document.getElementsByName("password").innerText,
"email":document.getElementsByName("email").innerText
}
if (json_data[0] == "" | json_data[1] == ""| json_data[2] == ""){
alert("数据填写不完整");
return false;
}
$.ajax({
type: "post",
url: "",//我发不了url
data: json_data,
dataType: "json",
success: function (response) {
if (JSON.parse(response)["message"] == "error"){
alert("注册失败");
}
else{
alert("注册成功")
}
}
});
}
document.querySelector("#submit").addEventListener("click",send_data)
然而,我发现只要引入了Jquery,原来JS的DOM好像操作不了或者事件监听用不了,请大佬告诉我这是怎么回事,谢谢!