removeAttribute('style')在iOS中不起作用,如何解决?

时间:2013-09-20 12:06:34

标签: javascript ios css

我有该网站的移动版本。我使用touchemove事件使用-webkit-transform将页面向左和向右移动。此变换是元素的内联属性。在touchend我使用document.getElementById('element').removeAttribute("style");,但它不适用于手机和平板电脑。

如何解决? 谢谢!

2 个答案:

答案 0 :(得分:2)

有时,如果您一次进行更多更改,removeAttribute似乎无效。而是使用类似这样的setAttribute方法:

document.getElementById('element').setAttribute('style','');

getAttribute之前调用removeAttribute似乎也有效,但我建议不要删除默认属性。

Source

答案 1 :(得分:1)

我发现使用

element.getAttribute('style');
element.removeAttribute('style');
过去,

对我来说可靠。根据MDN使用removeAttribute优先于使用setAttribute将其设置为空值(但公平地说,文档实际上并不是说为什么这是优选的)。

  

您应该使用removeAttribute,而不是使用setAttribute - https://developer.mozilla.org/en-US/docs/Web/API/element.removeAttribute设置属性值null