//*************************************//
// Create a label by defining the Method
//*************************************//
VaR createlabel = function (ID, name, value ){
VaR label_var = Document. createelement ("label ");
VaR label_id = Document. createattribute ("ID ");
Label_id.nodevalue = ID;
VaR label_text = Document. createtextnode (value );
Label_var.setattributenode (label_id );
VaR label_css = Document. createattribute ("class ");
Label_css.nodevalue = "select_css ";
Label_var.setattributenode (label_css );
Label_var.appendchild (label_text );
Return label_var;
}
//*************************************//
// Define a method to create an input tag (mainly text)
// ID, name, value, and type represent the ID of the created tag,
// Name, value, Type)
// Bind the input method event. The binding method is as follows (multiple event methods can be bound simultaneously ):
// "Onchange = alert ('this value is change success! '); | Onblur = alert ('this value is the beautiful one! ');"
//*************************************//
VaR createinput = function (ID, name, value, type, width, height, event ){
VaR var_input = NULL;
VaR input_event_attr_ie = "";
If (event! = NULL & event! = ""){
VaR event_array_ie = event. tostring (). Split ('| ');
For (VAR I = 0; I <event_array_ie.length; I ++ ){
VaR event_ie = event_array_ie [I]. Split ('= ');
Input_event_attr_ie + = "" + event_ie [0] + "= ''";
}
}
Try {// define variables to ensure compatibility between ie6.0 and ie7.0.
Var_input = Document. createelement ("<input" + input_event_attr_ie + "> ");
} Catch (e ){
Var_input = Document. createelement ("input ");
}
VaR input_id = Document. createattribute ("ID ");
Input_id.nodevalue = ID;
VaR input_name = Document. createattribute ("name ");
Input_name.nodevalue = Name;
VaR input_type = Document. createattribute ("type ");
Input_type.nodevalue = type;
VaR input_value = Document. createattribute ("value ");
Input_value.nodevalue = value;
VaR input_style = Document. createattribute ("style ");
VaR input_style_str = "";
If (width! = NULL & width! = ""){
Input_style_str + = "width:" + width + "PX ;";
} Else {
Input_style_str + = "width: 30px ;";
}
If (height! = NULL & height! = ""){
Input_style_str + = "height:" + height + "PX ;";
}
If (event! = NULL & event! = ""){
VaR event_array = event. tostring (). Split ('| ');
For (VAR I = 0; I <event_array.length; I ++ ){
VaR events = event_array [I]. Split ('= ');
VaR input_event = Document. createattribute (events [0]);
Input_event.nodevalue = events [1];
Var_input.setattributenode (input_event );
}
}
Var_input.setattributenode (input_type );
Input_style.nodevalue = input_style_str;
Try {
Var_input.setattributenode (input_style );
} Catch (e ){
Width = (width = NULL | width = "")? "30": width;
Var_input.setattribute ("width", width );
If (height! = NULL & height! = ""){
Var_input.setattribute ("height", height );
}
}
// If (readonly! = ""){
// Var input_readonly = Document. createattribute ("readonly ");
// Input_readonly.nodevalue = "readonly ";
// Var_input.setattributenode (input_readonly );
//}
Var_input.setattributenode (input_id );
Var_input.setattributenode (input_name );
Var_input.setattributenode (input_value );
Return var_input;
}
//************************************** ****************************//
// Define a method to create a select box label;
// ***** ID indicates the tag ID
// ***** Name indicates the name of the tag
// ***** Options indicates the option to bind the tag (for example, "0231a563-Professional Services | 02312177-maintenance services | ...... ")
// ***** Splitstr indicates the character used to separate options (for example, '| ')
// ***** Splitchar indicates the delimiter used to separate key-value pairs (for example :'-')
// ***** Event indicates the event corresponding to this tag (when event = NULL, this tag is not bound to an event)
//************************************** ****************************//
VaR createselect = function (ID, name, options, splitstr, splitchar, event, selectedvalue ){
VaR var_select = NULL;
Try {// handle ie6.0 and ie7.0 compatibility issues.
Var_select = Document. createelement ("<select onchange =''> ");
} Catch (e ){
Var_select = Document. createelement ("select ");
}
VaR select_id = Document. createattribute ("ID ");
Select_id.nodevalue = ID;
VaR select_name = Document. createattribute ("name ");
Select_name.nodevalue = Name;
If (event! = NULL & event! = Undefined & event! = ""){
VaR select_change = Document. createattribute ("onchange ");
Select_change.nodevalue = event;
Var_select.setattributenode (select_change );
}
Var_select.setattributenode (select_id );
Var_select.setattributenode (select_name );
Try {
Var_select.setattribute ("width", "100px ");
} Catch (e ){
VaR select_css = Document. createattribute ("class ");
Select_css.nodevalue = "select_css ";
Var_select.setattributenode (select_css );
}
Splitstr = (splitstr = "" | splitstr = NULL )? "|": Splitstr;
Splitchar = (splitchar = "" | splitchar = NULL )? "-": Splitchar;
If (options! = NULL & options! = Undefined & options. tostring ()! = ""){
Options = (options. tostring (). lastindexof (splitstr) + 1 = options. tostring (). Length )? Options. tostring (). substr (0, options. tostring (). Length-1): options;
VaR arrayoption = options. tostring (). Split (splitstr );
For (VAR I = 0; I <arrayoption. length; I ++ ){
VaR temp_value = arrayoption [I]. Split (splitchar );
VaR option = Document. createelement ("option ");
VaR option_value = Document. createattribute ("value ");
Option_value.nodevalue = temp_value [0];
VaR option_text = Document. createtextnode (temp_value [1]);
Option. setattributenode (option_value );
Option. appendchild (option_text );
Var_select.appendchild (option );
If (selectedvalue! = NULL & selectedvalue! = ""){
If (temp_value [0] = selectedvalue | temp_value [1] = selectedvalue ){
Var_select.options [I]. Selected = true;
}
}
}
}
Return var_select;
}
//************************************** *************//
// Define a method to create a <A> label;
// ***** ID indicates the unique ID of a tag
// ***** Name indicates the name of the tag
// ***** Value indicates the text (name) displayed for the label)
// ***** Event indicates the event corresponding to the tag (when event = NULL, the event is not bound)
// ***** Href indicates the link property of the tag.
//************************************** *************//
VaR createa = function (ID, name, value, event, href, target ){
VaR var_a = NULL;
Try {
Var_a = document. createelement ("<a onclick = ''target = '_ blank'>"); // The value must be "<a onclick = 'alert () '> "this method does not support ie6.0 or ie7.0.
} Catch (e ){
Var_a = Document. createelement ("");
}
VaR a_id = Document. createattribute ("ID ");
A_id.nodevalue = ID;
VaR a_name = Document. createattribute ("name ");
A_name.nodevalue = Name;
Href = (href = NULL | href = "")? ("Javascript: void (0);" | "#"): href;
VaR a_href = Document. createattribute ("href ");
A_href.nodevalue = href;
VaR a_text = Document. createtextnode (value );
Var_a.setattributenode (a_href );
Var_a.setattributenode (a_id );
Var_a.setattributenode (a_name );
If (target! = NULL ){
VaR target_href = Document. createattribute ("target ");
Target_href.nodevalue = "_ blank ";
Var_a.setattributenode (target_href );
}
If (event! = "" & Event! = NULL & event! = Undefined ){
VaR a_click = Document. createattribute ("onclick ");
A_click.nodevalue = event;
Var_a.setattributenode (a_click );
}
Var_a.appendchild (a_text); // note the order of binding this value. It can only be placed at the end of the binding (otherwise, ie6.0 and ie7.0 are not supported)
Return var_a;
}
//************************************** ****//
// Define the method to determine whether the input value is a number;
// ******* When flag = true, judge whether the input value is an integer;
//************************************** ****//
VaR check_is_num = function (OBJ, flag ){
VaR flag_var = false;
VaR num =/^ \ D + $/; // ^ \ +? [1-9] [0-9] * $ /;
// Flag_var =/^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ /. test (OBJ );
Flag_var =/^ \ D + (\. \ D + )? $/. Test (OBJ );
If (FLAG ){
Flag_var = num. Test (OBJ );
}
Return flag_var;
}
// Define a method to delete a node.
VaR removerowitem = function (OBJ ){
VaR rowtr = obj. parentnode. parentnode;
Try {
Rowtr. removenode (true );
} Catch (e ){
Rowtr. parentnode. removechild (rowtr );
}
}
String. Prototype. Trim = function (){
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}