Home >Web Front-end >JS Tutorial >Use javascript to add control custom attribute parsing_javascript skills

Use javascript to add control custom attribute parsing_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:12:301342browse

As mentioned before, adding custom attributes to HTML elements is done manually in the HTML control. In fact, it can be added dynamically in javascript: If there is a text box:

Copy code The code is as follows:



If you want to add the idvalue attribute (the value is "custom value"), you can write this in javascript:
Copy Code The code is as follows:

var txt = document.getElementById("txtInput");
txt.setAttribute("idvalue","custom value" );

The first parameter in setAttribute specifies the name of the custom attribute, and the second parameter is the initial value

The code is as follows:

Copy codeThe code is as follows:



; Add control custom attributes with javascript