如何通过javascript从CSS类中获取样式属性ime-mode?

时间:2016-01-22 08:58:45

标签: javascript html css

我输入了cssclass imeoff,如

.imeoff{ime-mode: disabled}

我想使用

读取属性ime-mode
style = window.getComputedStyle(element),
    top = style.getPropertyValue('ime-mode');

但上面的代码只能在IE和Firefox上运行,而不是在Chrome上运行。

你有什么建议吗?

2 个答案:

答案 0 :(得分:0)

“ime-mode”是在某些浏览器中稍微实现的属性,这是有问题的,并且被本规范正式废弃。

Chrome不支持ime模式 enter image description here

有一个新的DOM API CSS.supports来检查CSS属性的有效性。 FF,Opera(作为supportCSS)和Chrome Canary已经实现了这种方法。

尝试CSS.supports("ime-mode", "disabled"),这将返回false。

答案 1 :(得分:0)

您的代码很好,我不认为Chrome会将ime-mode识别为有效的css属性,请查看fiddle

function getTheStyle(styleName){
    var elem = document.getElementById("elem-container");
    var theCSSprop = window.getComputedStyle(elem,null).getPropertyValue(styleName);
    alert( theCSSprop );
    document.getElementById("output").innerHTML = theCSSprop;
   }
  getTheStyle( "height" ) ;
    getTheStyle( "ime-mode" ) ;

您无法阅读无效的because

属性
  

Javascript只能访问DOM,而不能访问代码。所以不,有   无法从浏览器本身的javascript访问属性   不支持。

相关问题