How to add a custom attribute to a HTML control.
<input type="text" validate="xyz"></input&开发者_JS百科gt;
I want to add a new attribute to the HTML control. validate here is the custom attribute.
Just add it.
HTML will ignore attributes it doesn't "know" about, so long as the markup is valid.
If you're using html5, you can use:
data-customAttributeName="whatever value"
The data-
prefix is mandatory, but you can follow it up with anything you like (so long as it's a valid html character string (a-z, 0-9, underscore and hyphen1).
Beyond that, though, it's of little importance since html will ignore attributes it doesn't understand or simply can't parse. Custom attributes will likely, though, throw validation errors (unless you define and specify a custom DTD).
- There's probably others, but I can't remember exactly.
精彩评论