首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

ajax交付现有表单

2012-06-26 
ajax提交现有表单真的是差不多快一年没写博客了,今天重新拾起程序,做个笔记:jQuery的Form插件有两种方法,a

ajax提交现有表单
真的是差不多快一年没写博客了,今天重新拾起程序,做个笔记:

jQuery的Form插件有两种方法,ajaxForm和ajaxSubmit方法。

通过ajaxForm很容易就可以把表单升级为ajax提交方式。

$(function{
$("form1").ajaxForm(function(){
        $("#request").html("表单提交成功").show();
})
})

用Submit同样也能完成这样的操作。

$(function{
$("form1").submit(function(){
       $(this).ajaxSubmit(function(){
             $("#request").html("表单提交成功").show();
});
      return false;
})
})

HTML我们可以这样写:


<form id="form1" method="post" action="ajaxfrom.php">
<input name="username" type="text">
<input name="password" type="password">
<input type="submit" name="submit">
</form>
<div id="request" style="display:none;"></div>

前提我们还要引进两个js


<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>

热点排行