form 表单的验证与特效

//页面装载完成
$(document),ready(function{    
alert("ceshi");   //测试一下

$("#verifyDutton").click(function(){      //  通过id找到button节点  再执行click时间
var userName = $("#userName").val();     // 获取文本框节点的值
if(userName == ""){
alert("用户名不能为空!");
}else{ 不会出现乱码
$.get("http:127.0.0.1:8080/jQuery/UserVerifyuserName="+encodrURl(encodrURl(userName)),null,function(response){    // 服务器端接受数据 $.get  和 $.post 2中方法
//  response 接收服务器端返回的数据  填充到div中
$("#result").html(response);

});
}

});

$("#userName").keyup(function(){ // 找到文本框 执行键盘弹起事件
         // userName:jquery对象
var value = $(this).val();    // 获取当前文本框的内容
if(value == ""){
// 值为空让边框变成红色。。。
$(this).addClass("userText");
}else{
//去掉边框和背景图
$(this).removeClass("userText");
}

});

});


css加载的样式类
.userText{
    border:1px solid red    // 边框是:1像素;实线的;红色

    background-image:url();   // 加载图片的路径
    background-repeat:repeat-x;   //图片在横向上不断的重复
    background-position:botton:   //图片在文本框的下方加载

}

HTML 代码
<body>
   请输入用户名:<input type="text" id="userName" class="userText"/>
                 <input type="button" value="校验" id="verifyButton"/>
   <div id="result"></div>    // 用户名可以使用
</body>

你可能感兴趣的:(jquery)