[英]element.setAttibute() method how to make it work in I.E?
I am setting the style attribute of a text via js element.setAttribute() method with name=style and value="my modifications to the style of text" 我通过js element.setAttribute()方法设置文本的样式属性,其中name = style和value =“我对文本样式的修改”
it is working well in browsers other than IE .. 在IE浏览器以外的其他浏览器中都可以正常工作。
In order to make it possible ,what should i do ? 为了使之成为可能,我该怎么办?
for your information im modifying these attributes -- text-align,text-decoration,font-style,font-weight,font-size.... 供您修改这些属性的信息-文本对齐,文本装饰,字体样式,字体粗细,字体大小...
I will be happy if someone guides me thank you.. 如果有人指导我,我会很高兴的。
Another way for IE which "preserve" the ordinary syntax of CSS is cssText
property: IE“保留” CSS普通语法的另一种方法是cssText
属性:
element.style.cssText = "text-align: center; text-decoration: underline; font-size: 120%;";
Official documentation: http://msdn.microsoft.com/en-us/library/ms533698(v=vs.85).aspx 官方文档: http : //msdn.microsoft.com/zh-cn/library/ms533698(v=vs.85).aspx
Just avoid setAttribute
. 只是避免setAttribute
。 It does nothing that can't be done though other methods. 它没有其他方法无法完成的工作。
element.style.textAlign = 'left';
for example. 例如。
That said, you are almost certainly better off predefining your styles and then causing them to be applied with: 也就是说,您几乎可以肯定,最好预先定义样式,然后将其应用于:
element.className += 'someClass';
… or a library that implements addClass
and removeClass
methods. …或实现addClass
和removeClass
方法的库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.