req.setAttribute(“msg”,“验证码错误!!”);
setAttribute是赋值,如上就是将 验证码错误!! 赋值给msg
getAttribute getAttribute(“msg”);取出msg的值,为 验证码错误!!
在IE中是不认识class属性的,需改为className属性,同样,在Firefox中,也是不认识className属性的,Firefox只认识class属性,所以通常做法如下:
element.setAttribute(****class****, value); *//for firefox*
element.setAttribute(className, value); *//for IE*
IE:可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性
例如:设置 input 元素的 type 属性:document.getElementsByTagName(“input”)[0].setAttribute(“type”,“button”);
*Firefox:只能使用getAttribute()获取自定义属性.*
解决方法:统一通过getAttribute()获取自定义属性
document.getElementById(‘box’).getAttribute(‘id’);****//获取元素的 id 值****
更多 dblog.csdn.net/pedrojuliet/article/details/53149620