用于应用css的Java脚本代码 [英] Java script code to apply css

查看:80
本文介绍了用于应用css的Java脚本代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function ShowDescription(id,spanid) {
       document.getElementById('discription').innerHTML = id.innerHTML;
     
   }










<ul id='tabs'>
    <li><a href='javascript:ShowDescription(divCourse3,span1);'><span id='span1' class='first focus'>
        Overview</span></a></li>
    <li><a href='javascript:ShowDescription(divCourse4,span2);'><span id='span2' class='last'>
        Curriculum</span> </a></li>
</ul>







我的要求是当用户单击函数spanID在paremeter中传递给函数时,所以在这里我需要使用javascript更改finss的css类。所以,如果有人知道该怎么做,请帮助我。



提前谢谢




My requirement is that when user click on function spanID is passed in paremeter to function, so here i need to change the css class of finction using javascript. so if anyone knows how to do that plz help me

Thanks in advance

推荐答案

我们可以轻松使用javascript更改元素的css类。我不确定你是什么意思更改css类的finction。



你可以改变任何元素的css类为



要用一个或多个新类替换所有现有类,请设置className属性:

We can easily change the css class of an element using javascript. I am not sure that what do you mean by "change the css class of finction ".

You can change the css class of any element as

To replace all existing classes with one or more new classes, set the className attribute:
document.getElementById("MyElement").className = "MyClass";





要为元素添加其他类:



要在不删除/影响现有值的情况下向元素添加类,请添加空格和新类名,如下所示:



To add an additional class to an element:

To add a class to an element, without removing/affecting existing values, append a space and the new classname, like so:

document.getElementById("MyElement").className += " MyClass";







如果这可以解决您的问题,请告诉我




Let me know if this resolves your problem


function ShowDescription(id,spanid){

var elm = document.getElementById(spanid);

elm.removeAttribute(class );

elm.setAttribute(class,newClass);



}
function ShowDescription(id,spanid) {
var elm = document.getElementById(spanid);
elm.removeAttribute("class");
elm.setAttribute("class","newClass");

}


这篇关于用于应用css的Java脚本代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆