$(document).ready(function(){
//HTML()替换 HTML函数
//append()追加 :input = :text,:password
$(":text,:password").blur(function(){
var v = $(this).val();
$(this).next().remove();
if(v==""){
//$(this).parent().html("用户名不能为空");
var name = $(this).attr("name");
$(this).parent().append("<font color='red'>"+name+"不能为空");
}
});
});
//HTML()替换 HTML函数
//append()追加 :input = :text,:password
$(":text,:password").blur(function(){
var v = $(this).val();
$(this).next().remove();
if(v==""){
//$(this).parent().html("用户名不能为空");
var name = $(this).attr("name");
$(this).parent().append("<font color='red'>"+name+"不能为空");
}
});
});
本文介绍了一个使用jQuery实现的简单输入验证脚本。当文本框或密码框失去焦点时,该脚本会检查是否输入了内容,并在为空的情况下显示错误提示。此示例展示了如何利用jQuery的HTML和append方法来更新DOM元素。
1万+

被折叠的 条评论
为什么被折叠?



