改变多个类名 [英] changing multiple classnames

查看:69
本文介绍了改变多个类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我们有这个:


< div class =" some_class some_other_class">


是吗可以改变*一个*的类名。


Jeff

Let''s say we have this:

<div class="some_class some_other_class">

Is it possible to change *one* of the classnames.

Jeff

推荐答案

Jeff< jeff @ spam_me_not .comwrites:
Jeff <jeff@spam_me_not.comwrites:

假设我们有这个:


< div class =" some_class some_other_class" >


是否可以更改* one *的类名。
Let''s say we have this:

<div class="some_class some_other_class">

Is it possible to change *one* of the classnames.



如果这是一个问题:是的。


myDiv.className.replace(/ \\\ netome_other_class \ b /,something_else);


-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

If that''s a question: yes.

myDiv.className.replace(/\bsome_other_class\b/,"something_else");

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Joost Diepenmaat< jo *** @ zeekat.nlwrites:
Joost Diepenmaat <jo***@zeekat.nlwrites:

myDiv.className.replace(/ \\\ netome_other_class \b /," something_else");
myDiv.className.replace(/\bsome_other_class\b/,"something_else");



那应该是:


myDiv.className = myDiv.className.replace(/ \\\ netome_other_class \ b /,something_else);


-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

That should ofcourse be:

myDiv.className = myDiv.className.replace(/\bsome_other_class\b/,"something_else");

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Jeffaécrit:
Jeff a écrit :

假设我们有这个:


< div class = some_class some_other_class>


是否可以更改* one *的类名。
Let''s say we have this:

<div class="some_class some_other_class">

Is it possible to change *one* of the classnames.



< div id =" somewhere" class =" some_class some_other_class">

< script type =" text / javascript">

function changeClass(what,original,newOne){

what = document.getElementById(what);

what.className = what.className.replace(original,newOne);

}

< / script>

< button onclick =" changeClass(''somewhere'',''some_other_class'',''new_class'')">

更改1

< / button>

< button onclick =" changeClass(''somewhere'',''some_class'' ,''new _other_class'')">

更改2

< / button>


-

sm

<div id="somewhere" class="some_class some_other_class">
<script type="text/javascript">
function changeClass(what, original, newOne) {
what = document.getElementById(what);
what.className = what.className.replace(original, newOne);
}
</script>
<button onclick="changeClass(''somewhere'',''some_other_class '',''new_class'')">
change 1
</button>
<button onclick="changeClass(''somewhere'',''some_class'',''new _other_class'')">
change 2
</button>

--
sm


这篇关于改变多个类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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