手机端点击注册按钮无反应估计是前端的问题,请教,网站:http://tou365.cn/initnode/sign_in.html
用的是BootStrap5,代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>注册新用户</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/popper.js/2.9.3/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.min.js"></script>
<script> function oncheck(form){
if(form.uname.value =='' && form.pwd.value =='' || form.uname.value =='' && form.pwd.value !='' )
{alert('用户名不能为空哈!')
}; if(form.uname.value !='' && form.pwd.value =='') {alert('密码不能为空哈')
};if(form.uname.value =='' && form.pwd.value ==''){ alert('用户名与密码不能为空哈')}
}</script>
</head>
<body>
<div style="width:130px;margin:0 auto;font-size:xx-large;margin-top: 20px;">开源社区</div>
<div class="container" style="width: 250px;margin-top: 20vh;border:1px solid rgba(128, 128, 128, 0.831);border-radius: 20px;padding:30px;" >
<h5>用户注册</h5>
<form action="" class="" onsubmit="oncheck(this);return false;const num=1">
<input type="text" name="uname" id="user" class="form-control" placeholder="用户名">
<br>
<input type="text" name="pwd" id="pwd" class="form-control" placeholder="密码">
<button class="btn btn-primary" style="margin-top: 20px;" >注册</button>
</form>
</div>
<script>
document.querySelector('.btn').onclick = function(){
//e.stopPropagation()
const name = document.querySelector('#user').value
const pwd = document.querySelector('#pwd').value
const xhr = new XMLHttpRequest()
xhr.open('post','http://127.0.0.1:3007/api/reguser')
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
xhr.send(
'username='+name+'&password='+pwd
)
xhr.onreadystatechange = function(){
if(xhr.readyState ===4){
if(xhr.status >=200 && xhr.status <300){
getjson('message')
function getjson(key){
var val = xhr.responseText
//var va = {"name":"傅红雪","age":"24","profession":"刺客"}//
var finval = jQuery.parseJSON(val)
console.log(finval)
console.log(typeof(finval))
var eValue=eval('finval.'+key)
alert(eValue);
if(eValue =='注册成功!'){window.location.href = './login_in.html'}
}
//console.log(val)
// jsonObj=val.substring(1,val.length-1);
//console.log()
//alert(msg)
}
}
};
}
</script>
</body>
</html>