PreviousArticleDiscussed and usedJavascriptTo manipulateHtmlThe custom attribute of the elementHtmlIn addition toHtmlCan a customHtmlWhat about elements? The answer is yes.
CustomHtmlElements and the system's ownHtmlThe element has the same position and can be usedDocument. getelementbyidThe difference is that the customHtmlElements are invisible, similar to hidden controls.
Use customHtmlElement, we can create a variety of hidden controls, not necessarily limitedInputOfHiddenElement. In addition, it can also be used for some specific needs!
For exampleHtmlDirectly create on the page:
LikeHtmlAdd the element as follows:
VaR Cy = Document. createelement ( " Yyy " );
Cy. ID = " Customcontrol_yyy " ;
Cy. Value = " Custom element yyy " ;
Cy. Checked = True ;
Document. Body. appendchild (CY );
2) UseJavascriptTo operate:
Alert (document. getelementbyid ("customcontrol_yyy"). value );
Alert (document. getelementbyid ("customcontrol_yyy"). Checked );
Here,FirefoxDirect values are supported, but not required.AttributesAttribute Set.
CodeAs follows:
< Html >
< Head >
< Title > Use JavaScript to define and operate custom HTML elements </ Title >
< Script Language = "JavaScript" >
Function Getxxxvalue ()
{
// Alert (document. getelementbyid ("customcontrol_xxx"). Value); // can be used in IE
Alert (document. getelementbyid ( " Customcontrol_xxx " ). Attributes [ " Value " ]. Value ); // IE Firefox can be used
}
// IE Firefox can be used
Function Createyyycontrol ()
{
VaR Cy = Document. createelement ( " Yyy " );
Cy. ID = " Customcontrol_yyy " ;
Cy. Value = " Custom element yyy " ;
Cy. Checked = True ;
Document. Body. appendchild (CY );
Alert (document. getelementbyid ( " Customcontrol_yyy " ). Value );
Alert (document. getelementbyid ( " Customcontrol_yyy " ). Checked );
}
</ Script >
</ Head >
< Body >
< Xxx ID = "Customcontrol_xxx" Value = "Custom element XXX" > </ Xxx >
< Input Type = "Button" Value = "Get xXx element value" Onclick = "Getxxxvalue ();" >
< Input Type = "Button" Value = "Generate the YYY element and obtain the value of this element" Onclick = "Createyyycontrol ();" >
</ Body >
</ Html >
Source code: Http://files.cnblogs.com/redleaf1995/CustomHtmlControl.rar