如果我要通过JS进行元素的class赋值。要怎么样才能做到兼容性最好?
我用ele.className="style"在FF下无效

解决方案 »

  1.   

    没有问题a
    <style>
    .a{color:#000}
    .b{color:#f00}
    </style>
    <input onclick="this.className='b'" class="a" value="xxx"/>
      

  2.   


    ele.style.className="style"就行了 。
      

  3.   

    className ff也支持的,可能问题不是出在这里.
      

  4.   

    是的。className是通用的呀。看看是不是其它方面的问题。
      

  5.   

    较早版本的FF并不支持className,试试
    ele.setAttribute(document.all ? 'className' : 'class', 'style');
      

  6.   

    但是在IE下是支持的啊。大家可以看一下这里的效果:http://www.net1573.com/demo/liu
      

  7.   

    你的css有一个地方写错了!.hidden{filter:alpha(opacity=50);opacity=0.50;width:138px; height:120px; border:none;}应改为: .hidden{filter:alpha(opacity=50);opacity:0.50;width:138px; height:120px; border:none;}
      

  8.   

    className是通用的
    楼主看看其他地方也没有问题吧
      

  9.   

    className直接赋值是没有问题的,但是getAttribute和setAttribute,FF只能用class,IE只能用className