jQuery学习笔录8(jQuery中的表单操作)

25 篇文章 0 订阅
23 篇文章 0 订阅

1  失去焦点 flur()

2 append(),appendTo() 插入内容

3 id ,value值等等

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQueryFormS.aspx.cs" Inherits="jQueryForm_jQueryFormS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script src="../scriptJquery/jquery-1.3.2.min.js"></script>
    <style>
        .high{
            color:red;
        }
    </style>
</head>
<body>
    <form method="post" action="jQueryFormS.aspx">
    <div class="int">
     <label for ="username">用户名:</label>
     <input type="text" id="username" class="required" />
    </div>
    <div class="int">
        <label for="email" >邮箱:</label>
        <input type="text" id="email" class="required" />
    </div>
    <div class="int">
        <label for="personinfo">个人资料</label>
        <input type="text" id="personinfo" />
    </div>
    <div class="sub">
        <input type="submit" value="提交" id="send" /><input type="reset" id="res" />
    </div>
    </form>
</body>
</html>
<script>
    $("form :input.required").each(function(){
        var required=$("<strong class='high'>*</strong>");
        $(this).parent().append(required);
    })
    //失去焦点
    $("form :input").blur(function(){
        //我想用id去查,就是说$(this).id。。啥的,语法没想起来
        if($(this).is("#username"))
        {
            if(this.value==""||this.value.length<6)
            {
                var errMsg="请输入至少6位的用户名";
                $(this).parent().append("<span class='onError'>"+errMsg+"</span>");//parent()是div
            }
            else
            {
                 var okMsg="OK";
                $(this).parent().append("<span class='onRight'>"+okMsg+"</span>");
                //append()前面是要选择的对象,后面是要在对象内插入的元素内容
                //appendTo()前面是要插入的元素内容,而后面是要选择的对象
            }
        }
        
    })
    $("form :input").focus(function(){ 
        $(this).parent().find(".onError").remove();
        $(this).parent().find(".onRight").remove();
    })
    
    $("#send").click(function(){console.info(0)
        $("form :input").parent().find(".onError").remove();
        $("form :input").parent().find(".onRight").remove();
        $("form .required:input").trigger("blur");console.info(1)
        var error=$("form .onError").length;console.info(2)
        if(error){console.info(3)
            return false;
        }
        console.info("ok success");
    })

</script>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值