The main function is to dynamically increase or decrease the input box, and supports detection of each input box. After each input box is input, an error message is displayed, concatenating strings to add all the content in the input box, splice the image in the format of "1234235 #34634234 #123525.
Webpage code:
The Code is as follows:
Js Code:
The Code is as follows:
$ (Function (){
// Initialization
InitFields ();
});
Function initFields (){
// Initialize the mobile phone
Var text = $ ('# mobile'). val ();
Var ss = text. split ("#");
If (ss. length> 0 ){
$ ('# Mobile_t'). val (ss [0]);
}
For (var I = 1; I Addinput ('mobile _ s_p ', 'mobile _ P', ss [I]);
}
}
/**
String concatenation
Src_id is the name of the source input, and dist_id is the id value of the target input.
*/
Function compose (src_name, dist_id ){
Var str = "";
Var ss = $ ('input [name = '+ src_name +'] '). each (function (I ){
If ($ (this). val ()! = "")
Str + = '#' + $ (this). val ();
});
Str = str. substring (1, str. length );
$ ('#' + Dist_id). val (str );
}
/**
Clone an input and display it in the specified container.
*/
Function addinput (id, p_id, text ){
Var mobile_p = $ ('#' + id). clone ();
Mobile_p.children ('input'). val (text );
Var delbt = $ (" ")
Delbt. bind ("click", function () {$ (this). parent (). remove ()});
Mobile_p.append (delbt)
$ ('#' + P_id). append (mobile_p );
Return false;
}
Function check1 (){
Compose ('mobile _ t', 'mobile ');
}
//
Function checkMobilephone (obj ){
If (obj = null ){
Return false;
}
Var span = $ (obj). parent (). children ('span ');
Var str = obj. value;
If (str = ""){
Span. text ('');
$ (Obj). removeClass ("inputError ");
Return false;
}
Var pattern =/^ 1 \ d {10} $ /;
If (! Pattern.exe c (obj. value) {// does not match.
Span. text ('mobile phone number entered incorrectly! '0000.css ("color", "red ");
$ (Obj). addClass ("inputError ");
Return false;
} Else {
Span. text ('');
$ (Obj). removeClass ("inputError ");
}
}
Introduce js files into html files
1
The Code is as follows: