112. The difference between setAttribute and getAttribute

req.setAttribute("msg","The verification code is wrong!!");

setAttribute is assignment, as above is the verification code error! ! Assign to msg

getAttribute getAttribute("msg"); Get the value of msg, the verification code is wrong! !

In IE, the class attribute is not recognized and needs to be changed to the className attribute. Similarly, in Firefox, the className attribute is also not recognized. Firefox only recognizes the class attribute, so the usual practice is as follows:

element.setAttribute(****class****, value); *//for firefox*

element.setAttribute(className, value); *//for IE*


IE: You can use the method of getting general attributes to get custom attributes, and you can also use getAttribute() to get custom attributes

For example: set the type attribute of the input element: document.getElementsByTagName("input")[0].setAttribute("type","button");

*Firefox: You can only use getAttribute() to get custom attributes.*

Solution: Get custom attributes uniformly through getAttribute()

document.getElementById('box').getAttribute('id');****//Get the id value of the element****

More dblog.csdn.net/pedrojuliet/article/details/53149620

Guess you like

Origin blog.csdn.net/weixin_43206161/article/details/112324189