如何使用JavaScript向HTML元素添加/更新属性? [英] How to add/update an attribute to an HTML element using JavaScript?

查看:80
本文介绍了如何使用JavaScript向HTML元素添加/更新属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种将使用JavaScript添加/更新属性的方法。我知道我可以用 setAttribute()函数,但不能在IE中使用。

I'm trying to find a way that will add / update attribute using JavaScript. I know I can do it with setAttribute() function but that doesn't work in IE.

推荐答案

您可以阅读这里关于属性在许多不同的浏览器,包括IE。

You can read here about the behaviour of attributes in many different browsers, including IE.

element.setAttribute()应该做的技巧,即使在IE 。你试试吗?如果它不工作,比可能
element.attributeName ='value'可能工作。

element.setAttribute() should do the trick, even in IE. Did you try it? If it doesn't work, than maybe element.attributeName = 'value' might work.

这篇关于如何使用JavaScript向HTML元素添加/更新属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆