封装input默认值修改的jquery插件

This commit is contained in:
Li Jianxuan 2012-12-25 09:12:01 +00:00
parent 194babb8ab
commit 3098e6f2f3
1 changed files with 34 additions and 42 deletions

View File

@ -352,49 +352,41 @@ function SelectInputTemplate(name){
} }
} }
(function( $ ){
$.fn.inputbg = function( options ) {
// Create some defaults, extending them with any options that were provided
var settings = $.extend( {
val : '姓名'
}, options);
this.each(function() {
if($(this).val() == '')
{
$(this).val(options.val);
}
});
this.bind('focus',function(){
if($(this).val() == options.val)
{
$(this).val('');
}
});
this.bind('blur',function(){
if($(this).val() == '')
{
$(this).val(options.val);
}
});
};
})( jQuery );
function InputTextSet(){ function InputTextSet(){
var def_val_name = "姓名" $('.contact_name').inputbg({'val':'姓名'});
var def_dom_name = ".contact_name"; $('.contact_email').inputbg({'val':'Email'});
$(def_dom_name).each(function(index, element) {
if($(this).val() == '')
{
$(this).val(def_val_name);
}
});
$(def_dom_name).bind('focus',function(){
if($(this).val() == def_val_name)
{
$(this).val('');
}
});
$(def_dom_name).bind('blur',function(){
if($(this).val() == '')
{
$(this).val(def_val_name);
}
});
var def_val_email = "Email"
var def_dom_email = ".contact_email";
$(def_dom_email).each(function(index, element) {
if($(this).val() == '')
{
$(this).val(def_val_email);
}
});
$(def_dom_email).bind('focus',function(){
if($(this).val() == def_val_email)
{
$(this).val('');
}
});
$(def_dom_email).bind('blur',function(){
if($(this).val() == '')
{
$(this).val(def_val_email);
}
});
} }
// Google Map Part // Google Map Part