简体   繁体   English

element.setAttibute()方法如何使其在IE中工作?

[英]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. …或实现addClassremoveClass方法的库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用“全选”运算符(即“ *”)和jquery时获得点击元素? - how to get clicked element while using “select all” operator i.e “ * ” using jquery? jQuery:如何覆盖特定元素的默认方法(即html,append)? - jQuery: how to override default methods (i.e html, append) for particular element? 如何添加方法,即使用jQuery以表格形式获取/发布 - how to add method i.e get/post in a form using jquery 如何在所有设备(例如台式机和移动浏览器)上制作具有一定高度和100%宽度的iframe - how to make an iframe with some height and 100% width across all devices i.e desktop and mobile browsers 限制字段​​的功能在mozilla和IE中不起作用 - function that limits fields does not work in mozilla and I.E 这个jQuery代码如何工作(即将什么放入变量中)? - How does this jQuery code work(i.e what would be put into the variables)? 按钮内的 onChange 和 onClick 在 IE 上不起作用 - onChange and onClick inside a button doesn't work on I.E Lodash:返回其值(即Array)中有给定元素(即字符串)的对象的第一个键 - Lodash : return first key of object whose value(i.e Array) has a given element (i.e string) in it 如果我们有极长的水平滚动页面,如何在最后一个元素的末尾添加边距/填充,即空间? - How to add margin/padding i.e space right to the end of the last element if we have extremely long horizontal scrolling page? 如何在angular.js中使用带有代码的笑脸[即:-)]? - how to use smilies with codes[i.e :-) ] in angular.js??
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM