国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery 表單事件之submit()事件

submit 事件

定義和用法

當(dāng)提交表單時(shí),會(huì)發(fā)生 submit 事件。

該事件只適用于表單元素。

submit() 方法觸發(fā) submit 事件,或規(guī)定當(dāng)發(fā)生 submit 事件時(shí)運(yùn)行的函數(shù)。

語法

$('').submit()

下面我們來詳細(xì)分析一下,看下面代碼

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>submit</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
    <form action="#" method="post" name="form">
        用戶名:<input type="text" placeholder="請(qǐng)輸入用戶名"></br></br>
        用戶名:<input type="password" placeholder="請(qǐng)輸入密碼"></br></br>
        <input type="submit" value="提交">
    </form>

</body>
</html>

如上代碼,我們表單沒有加入事件,但是默認(rèn)會(huì)提交到一個(gè)地方,也就是后面我們學(xué)到php的腳本語言時(shí),會(huì)做對(duì)表單的處理

那么我們?cè)趺丛诒卷撁孢M(jìn)行客戶端的處理,那么我就需要些jquery 的代碼,來進(jìn)行對(duì)表單的處理

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>submit</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
    <form action="#" method="post" name="form">
        用戶名:<input type="text" placeholder="請(qǐng)輸入用戶名"></br></br>
        用戶名:<input type="password" placeholder="請(qǐng)輸入密碼"></br></br>
        <input type="submit" value="提交">
    </form>

    <script>
        $('form').submit(function(){
            alert('error');
        })
    </script>
</body>
</html>

如上代碼,我們進(jìn)行表單提交,點(diǎn)擊按鈕,觸發(fā)submit 事件,彈出一個(gè)error的信息,這樣我們就可以在本頁面進(jìn)行對(duì)表單的處理,例如用戶名的規(guī)則,密碼的規(guī)則,不符合就不讓表單提交到另外的一個(gè)頁面進(jìn)行處理

繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>submit</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <form action="#" method="post" name="form"> 用戶名:<input type="text" placeholder="請(qǐng)輸入用戶名"></br></br> 用戶名:<input type="password" placeholder="請(qǐng)輸入密碼"></br></br> <input type="submit" value="提交"> </form> <script> $('form').submit(function(){ alert('error'); }) </script> </body> </html>
提交重置代碼