Js determines whether an element exists. This function is very practical in the project. I have collected and sorted out some common skills. For details, refer
1. Determine whether a form element exists (1)
The Code is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> if ("periodPerMonth" in document. theForm)
{
Return true;
}
Else {
Return false;
}
2. Determine whether the page element exists
The Code is as follows:
If (document. getElementById ("XXX "))
{
// Exists
}
3. Determine whether a form element exists (2)
The Code is as follows:
If (document. theForm. periodPerMonth)
{
// Exists
} Or
If (typeof (document. theForm. periodPerMonth) = "object ")
{
// Exists
}
4. Determine whether a form exists
The Code is as follows:
If (document. theForm)
{
// Exists
}
5. Use Jquery to write scripts
The Code is as follows:
If ($ ("# someID"). length> 0 ){
$ ("# SomeID"). text ("hi ");
}