Customizing HTML Tag Properties

Source: Internet
Author: User

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

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.