//网络验证 event默认事件
function query(el) {
return document.querySelector(el);
}
query("#form").addEventListener("submit",
function(e) {
let user = query("[name='username']").value.trim(); //trim
let copyright = query("[name='copyright']").checked;
if (!user || copyright === false) {
e.preventDefault();
alert("没有勾选协议或用户名为空!")
}else if (user.length<6){
e.preventDefault();
alert("密码不能小于六位!")
}
e.preventDefault();
console.log(user)
});
//三元表达式创建元素
function div(options={}){
let div=document.createElement("div");
div.style.width=options.width?options.width:"100px";
div.style.height=options.height?options.height:"100px";
div.style.backgroundColor=options.bgcolor?options.bgcolor:"#f6c600";
//在body下创建div
document.body.appendChild(div)
}
div({width:"300px"});