Adding a custom property to an HTML element is convenient, just add it to the angle brackets and be equal to the built-in attribute.
If we want to add property Idvalueto the TextBox element:
<input type= "text" id= "Txtinput" name= "Txtinput" value= "Custom Text" >
Just add: idvalue= "..." after the original control to become:
<input type= "text" id= "Txtinput" name= "Txtinput" value= "Custom Text" idvalue= "Custom Values" >
Idvalue can formally become the Txtinput attribute, and the status is equal to the other attributes.
As the following example, debug through in IE6:
<title> Custom Properties </title>
<script language= "JavaScript" >
function Showtext ()
{
Alert (Document.getelementbyidx ("Txtinput"). Value);
}
function Showvalue ()
{
Alert (Document.getelementbyidx ("Txtinput"). Idvalue);
}
</script>
<body>
<input type= "text" id= "Txtinput" name= "Txtinput" value= "Custom Text" idvalue= "Custom Values" >
<input type= "button" id= "Btnshowtext" name= "Btnshowtext" value= "Display text content" onclick= "Showtext ();" >
<input type= "button" id= "Btnshowvalue" name= "Btnshowvalue" value= "display text value" onclick= "Showvalue ();" >
</body>
But idvalue in Firefox can not pass, mainly because of the strict Firefox control, so these custom properties can not be recognized. After debugging, can only use Document.getelementbyidx ("Txtinput"). attributes["Idvalue"].nodevalue obtained, the method can also be used in IE. So, the same code for IE and Firefox is:
<title> Custom Properties </title>
<script language= "JavaScript" >
function Showtext ()
{
Alert (Document.getelementbyidx ("Txtinput"). Value);
}
function Showvalue ()
{
Alert (Document.getelementbyidx ("Txtinput"). attributes["Idvalue"].nodevalue);
}
</script>
<body>
<input type= "text" id= "Txtinput" name= "Txtinput" value= "Custom Text" idvalue= "Custom Values" >
<input type= "button" id= "Btnshowtext" name= "Btnshowtext" value= "Display text content" onclick= "Showtext ();" >
<input type= "button" id= "Btnshowvalue" name= "Btnshowvalue" value= "display text value" onclick= "Showvalue ();" >
</body>
Customizing HTML Tag Properties