<li>
<div class="inputMD" style="position: relative;">
<input class="phInput" type="text" />
<span class="phText" style="clear: both; height: 33px; line-height: 33px; color: #aaa; position: absolute; left: 10px; top: 5px;">手机号码/邮箱地址</span>
</div>
</li>
<li>
<div class="inputMD" style="position: relative;">
<input class="phInput" type="password" />
<span class="phText" style="clear: both; height: 33px; line-height: 33px; color: #aaa; position: absolute; left: 10px; top: 5px;">请输入密码</span>
</div>
</li>
function _placeholderText(phInput, phText) { //定义函数,传递2个参数——input输入框和text提示文本的id或者class
var $input = $(phInput);
var $text = $(phText);
$input.each(function() { //页面加载时遍历所有仿placeholder的input
var _this = $(this);
var _text = _this.siblings(phText);
if($.trim(_this.val()) == '') {
_this.val("");
_text.show();
} else {
_text.hide();
}
});
$text.on('click', function() { //点击提示信息,input获取焦点
$(this).siblings(phInput).focus();
});
$input.on('input propertychange blur', function() { //为input注册事件,value值改变(其实是属性发生变化)时以及失去焦点时判断value值是否为空
var _this = $(this);
if(_this.val() == '') {
_this.siblings(phText).show();
} else {
_this.siblings(phText).hide();
}
});
}
_placeholderText('.phInput', '.phText'); //调用函数
function inputJsDIY(obj, colorTip, colorTxt) { //定义函数,传递3个参数——DOM对象、提示文本的颜色值、输入文本的颜色值
colorTip = colorTip || '#aaaaaa';
colorTxt = colorTxt || '#666666';
obj.each(function() {
var _this = $(this);
_this.css({"color": colorTip}); //输入框颜色默认置为提示文本的颜色值
if($.trim(_this.val()) == "") { //判断value值是否为空,若为空则value值赋值等于提示文本
_this.val(_this.attr("phText"));
} else if(_this.val() != _this.attr("phText")) {
_this.css({"color": colorTxt}); //正常的输入文本颜色值
}
});
obj.on("focus", function() { //获取焦点时做判断
var _this = $(this);
var value = _this.val();
if(value == _this.attr("phText")) {
_this.val("");
}
_this.css({"color": colorTxt});
});
obj.on("blur", function() { //失去焦点时做判断
var _this = $(this);
var value = _this.val();
if($.trim(value) == "") {
_this.val($(this).attr("phText")).css({"color": colorTip});
}
});
obj.parents("form").on("submit", function() { //提交表单时去除提示文本(把提示文本置空)
obj.each(function() {
var _this = $(this);
if(_this.val() == _this.attr("phText")) {
_this.val("");
}
});
});
}
inputJsDIY($('.phInput'), '#aaa', '#666'); //调用函数
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有