Based on the selected data color, JavaScript searches the entire document for the selected data nodes (one or more data nodes can be selected as conditions)

Source: Internet
Author: User

/**
* Mark the color of the selected data as '# c90000' (the subsequent values are based on this color)
*/
Function selectcondition (element ){
VaR aelement = element. getelementsbytagname ("A") [0];
VaR STR = deletestylewithelement (aelement. parentelement, element );
If ('0' = Str ){
Alert ("the content of the current project has been filled in the text box! ");
} Else if ('1' = Str ){
If (aelement. innerhtml ){
If (aelement. innerhtml. indexof ('# c90000 ')! =-1 ){
Aelement. innerhtml = aelement. innertext;
} Else {
Aelement. innerhtml = '<font color = "# c90000">' + aelement. innertext + '</font> ';
}
}
}
}

/**
* Check whether the selection before the text box is selected.
*/
Function checkinput (element ){
VaR parenttr = element. parentelement;
VaR tdelements = parenttr. getelementsbytagname ("TD ");
VaR m = 0;
For (VAR I = 0; I <tdelements. length; I ++ ){
VaR aelement = tdelements [I];
If (aelement. innerhtml. indexof ('# c90000 ')! =-1 ){
M ++;
}
}
If (0! = M ){
Alert ("selected! Please cancel selection for custom input! ");
// For (VAR I = 0; I <tdelements. length; I ++ ){
// Var aelement = tdelements [I];
// If (aelement. innerhtml. indexof ('# c90000 ')! =-1
// & Aelement. innertext! = Element. innertext ){
// Aelement. getelementsbytagname ("A") [0]. innerhtml = aelement. innertext;
//}
//}
}
}

Function deletestylewithelement (parentelement, element ){
VaR STR = "";
VaR tdelements = parentelement. getelementsbytagname ("TD ");
VaR inputelements = parentelement. getelementsbytagname ("input ");
VaR inputvalue = "";
For (VAR I = 0; I <inputelements. length; I ++ ){
If (inputelements [I]. Value ){
Inputvalue + = inputelements [I]. Value + ",";
}
}
If (inputvalue. length> 1 ){
STR = '0 ';
} Else {
For (VAR I = 0; I <tdelements. length; I ++ ){
VaR aelement = tdelements [I];
If (aelement. innerhtml. indexof ('# c90000 ')! =-1
& Aelement. innertext! = Element. innertext ){
Aelement. getelementsbytagname ("A") [0]. innerhtml = aelement. innertext;
}
}
STR = '1 ';
}
Return STR;
}

 

 

/**
* Obtain all values of TD in the page node with the elementid ID, separated by commas (,).
* @ Param elementid
* @ Returns {string}
*/
Function gettdvalueforelement (elementid ){
VaR element = Document. getelementbyid (elementid );
VaR tdlist = element. getelementsbytagname ("TD ");
VaR conditionvalues = "";
If (null! = Tdlist & tdlist. length> 0 ){

For (VAR I = 0; I <tdlist. length; I ++ ){
VaR TD = tdlist [I];
If (TD. innerhtml. indexof ('# c90000 ')! =-1 ){
Conditionvalues + = TD. innertext + ',';
}
}
Conditionvalues = subrealvalue (conditionvalues );
}
 
Return conditionvalues;
}

/**
* Obtain the values in TD or input in the page node whose elementid is the ID (only data of a single TD node can be returned here)
* @ Param elementid
* @ Returns {string}
*/
Function gettdvaluewithinputforelement (elementid ){
VaR element = Document. getelementbyid (elementid );
VaR tdlist = element. getelementsbytagname ("TD ");
VaR conditionvalues = "";
VaR m = 0;
If (null! = Tdlist & tdlist. length> 0 ){
For (VAR I = 0; I <tdlist. length; I ++ ){
VaR TD = tdlist [I];
If (TD. innerhtml. indexof ('# c90000 ')! =-1 ){
If (M <= 0 ){
Conditionvalues = TD. innertext;
} Else {
Alert ("only one item can be selected here! ");
Return;
}
M ++;
}
}
Conditionvalues = subrealvalue (conditionvalues );
}
If (M = 0 ){
VaR inputlist = element. getelementsbytagname ("input ");
If (null! = Inputlist & inputlist. length> 0 ){
If (inputlist. Length = 1 ){
Conditionvalues = inputlist [0]. value;
} Else if (inputlist. Length = 2 ){
Conditionvalues = inputlist [0]. Value + "~ "+ Inputlist [1]. Value +" ";
}
}
}
Return conditionvalues;
}

 

 

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.