简体   繁体   English

getAttribute方法不能在IE中使用,但可以在其他浏览器中使用

[英]getAttribute method not working in IE but working in other browsers

I wrote a JavaScript to get the value of the class attribute using get Attribute method. 我编写了一个JavaScript,使用get Attribute方法获取类属性的值。 It's working and I satisfied with my requirement in all browsers except IE. 它正在运行,我对除IE之外的所有浏览器的要求都感到满意。

The text area component inserted dynamically in to a jsf page. 文本区域组件动态插入到jsf页面中。 Whenever onload we execute this JavaScript function to show text editor for text area. 每当加载时,我们都会执行此JavaScript函数来显示文本区域的文本编辑器。

Here is my JavaScript: 这是我的JavaScript:

  function showingRTFTextArea(){
   // alert("before Starting");
    var textareaEle=document.getElementsByTagName("textarea");
   // alert("Textarea fields:"+textareaEle.toString());
    for(var i=0;i<textareaEle.length;i++){
            var textareaObj=textareaEle[i];
            //alert(textareaObj.getAttribute('Class'));
            if(textareaObj.getAttribute('Class')=='rtfclass'){
                var nameOfEle=textareaObj.getAttribute('name');
                 CKEDITOR.inline(nameOfEle);
               //  alert("set the RTF");
            }
    }

对于IE,请尝试使用className而不是class。

if(textareaObj.getAttribute('className')=='rtfclass')

if you just want to test for the presence of a CSS class this works in all browsers: 如果您只想测试CSS类的存在,则可以在所有浏览器中使用:

if(textareaObj.classList.contains('rtfclass')){
//...

} }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM