一、form表单的基本使用
<!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>Document</title>
</head>
<body>
<form action="/login" target="_blank" method="post">
<input type="text " name="email_or_mobile">
<input type="password" name="password" id="">
<button type="submit">提交</button>
</form>
</body>
</html>
二、通过Ajax提交表单数据
<!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>Document</title>
<script src="./lib/jquery.js"></script>
</head>
<body>
<form action="/login" id="f1" >
<input type="text " name="user_name">
<input type="password" name="password" id="">
<button type="submit">提交</button>
</form>
<script >
$(function(){
// 第一种的方式
// $('#f1').submit(function(){
// alert('监听到了表单的提交事件')
// })
// 第二种方式
$('#f1').on('submit' , function(){
alert('监听到了表单的提交事件2')
})
})
</script>
</body>
</html>
<!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>Document</title>
<script src="./lib/jquery.js"></script>
</head>
<body>
<form action="/login" id="f1" >
<input type="text " name="user_name">
<input type="password" name="password" id="">
<button type="submit">提交</button>
</form>
<script >
$(function(){
// 第一种的方式
// $('#f1').submit(function(e){
// alert('监听到了表单的提交事件')
// e.preventDefault()
// })
// 第二种方式
$('#f1').on('submit' , function(e){
alert('监听到了表单的提交事件2')
e.preventDefault()
})
})
</script>
</body>
</html>