Input original version, later modified

Source: Internet
Author: User

(function ($) {
function Inputauto (obj) {
init={
Inputclass: ". Js_input",
Password_tag: "Password",
pswhtml: ' <input class= "input" type= "text" value= "" placeholder= ""/> ",
Pswclass: ' ADDPSW ',
Wrapclass: ' Psw_wrap ',
Wrap: ' <span></span> '
}
This.init=$.extend (Init,obj);
}

inputauto.prototype={
Main:function () {
var _this=this,i=this.init,
Initval= ";

$ (I.inputclass). each (function () {

Initval=_this.getholder (this);
_this.input_def (This,initval);
})
_this.focus ();
_this.blur ();
},
Focus:function () {
var _this=this,i=this.init, $tempInput;
$ (I.inputclass). On ("Focus", function () {
var init=$ (this). attr ("Data-placeholder"),
Initusr= "";

if (_this.getholder (this)! = "") {
Initusr=_this.getholder (this);
}else{
initusr=$ (This). attr ("Data-placeholder-old");
}

if ($ (this). val ()! = "" && $ (this). Val ()!=initusr && Init!=i.password_tag) {//have new input to save input value
$ (this). attr ("Data-userval", $ (this). Val ());
};

$ (this). Val ("");
$ (this). attr (' Data-placeholder-old ', initusr);

if (_this.placeholder ()) {
$ (this). attr (' placeholder ', ');
}

if (Init==i.password_tag) {
if (_this.navie () && $ (this). Hasclass (I.pswclass)) {//ie78 replaces the TXT element of PWD
var $prev =$ (this). Prev ();
var t=_this.getholder ($prev [0]);
var $tobj =$ (this). Prev ();

$tobj. Show (). Val (""). attr (' Data-placeholder-old ', t);
$ (this). attr (' Data-placeholder-old ', T). Hide ();
$tobj. focus ();

}else{
$ (this). attr ("type", "password");
}
}//
})
},
Blur:function () {
var _this=this,i=this.init;
$ (I.inputclass). On ("Blur", function () {
var init=$ (this). attr ("Data-placeholder"),
Holder=_this.getholder (This),
initusr=$ (This). attr ("Data-placeholder-old"),
usrval=$ (This). attr ("Data-userval");

if ($ (this). val () = = "" && (! ( _this.navie ()) | | Init!=i.password_tag)) {
Usrval?_this.input_def (This,usrval): _this.input_def (THIS,INITUSR);
};

if (Init==i.password_tag && (This). val () = = "" | | $ (this). Val () ==initusr)) {//password blank display prompt

if (_this.navie () &&!$ (this). Hasclass (I.pswclass)) {//ie78 under PWD element
Alert (Usrval)
$ (this). Next (). Show (). val (holder). End (). hide ();
}else{
$ (this). attr ("type", "text");
}
}
})
},
Placeholder:function () {
Return ' placeholder ' in document.createelement (' input ');
},
Input_def:function (obj,init) {
var _this=this,i=this.init;
$ (obj). Val ("");
if (!_this.placeholder ()) {
$ (obj). val (init);
if ($ (obj). attr ("type") = = = "Password") {
_this.chagetype (Obj,init);
}
}else{
$ (obj). attr (' placeholder ', init);
($ (obj). attr ("type") = = "Password")? $ (obj). Val (""): $ (obj). val (init);
}
},
Chagetype:function (obj,init) {
var _this=this,i=this.init;

If (_this.navie ()) {
if (!$ (obj). Parent (). Hasclass (I.wrapclass)) {
$ (obj). Wrap (I.wrap);
$ (obj). Parent (). addclass (I.wrapclass). Append (i.pswhtml). End (). Next (). addclass (I.pswclass). Val (init). attr (" ID "," psw_ "+$ (obj). attr (" id ")). attr (" Data-placeholder ", I.password_tag). End (). hide ();
}
}else{
if ($ (obj). attr ("type") = = "Password") $ (obj). attr ("type", "text");
}
},
Navie:function () {
if (navigator.appname = = "Microsoft Internet Explorer" && ( Navigator.appVersion.split (";") [1].replace (/[]/g, "") = = "MSIE7.0" | | Navigator.appVersion.split (";") [1].replace (/[]/g, "") = = "MSIE8.0")) {
return true;
} else{
return false;
}
},
Getholder:function (obj) {
var _this=this, initval= "";
if (!_this.placeholder ()) {
Initval= obj.attributes[' placeholder '].nodevalue;
}else{
initval=$ (obj). attr ("placeholder");
}
return initval;
}
}

var inputauto_inst=new inputauto ({inputclass: ". Input"});
Inputauto_inst.main ();

}) (JQuery);

Input original version, later modified

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.