200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 阻止表单提交 回车提交表单

阻止表单提交 回车提交表单

时间:2023-04-26 14:00:30

相关推荐

阻止表单提交 回车提交表单

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>文档碎片</title>

<script src = "jquery-1.11.0.min.js"></script>

</head>

<style>

.bg,form{

display: none;

}

.bg{

position: absolute;

left: 0;

right: 0;

top: 0;

bottom: 0;

height: 100%;

z-index: 2;

background-color: #000;

opacity: 0.5;

}

form{

position: absolute;

left: 50%;

top: 50%;

z-index: 99;

width: 472px;

height: 400px;

margin-left: -236px;

margin-top: -200px;

background-color: #fff;

}

</style>

<body>

<button id = "click">click</button>

<div class = "bg"></div>

<form name="testform" action="#" id="form">

What is your name?<br />

<input type="text" name="fname" />

<input type="text" name="fname2" />

<button type="submit" value="Submit">提交</button>

</form>

</body>

<script type="text/javascript">

$("#click").on("click",function(){

$(".bg").css("display","block");

$("form").css("display","block");

})

var form = document.getElementById('form');

form.onsubmit = function(){

if(($("input[name = 'fname']").val() == "aa") && ($("input[name = 'fname2']").val() == "bb")){

alert("提交成功!");

return true;

}else{

alert("提交失败!");

return false;

}

}

</script>

</html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。