请教js怎么动态改变一个对象的颜色

请教js怎么动态改变一个对象的颜色,第1张

用js方法来实现,代码为:document.getElementById("t").style.color="red"

说明:上面的"t"可以根据自己需要修改,具体代码参考:

<html>

<body>

<a name="t" class="STYLE2" id="t" onclick="chcolor()">登陆通行证</a>

<script type="text/javascript">

function chcolor(){

document.getElementById("t").style.color="red"

}

</script>

</body></html>

用JavaScript动态改变按钮文字上面的颜色

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function initArray() {

for (var i = 0i <initArray.arguments.lengthi++) {

this[i] = initArray.arguments[i]

}

this.length = initArray.arguments.length

}

var colors = new initArray(

"red",

"blue",

"green",

"purple",

"black",

"tan",

"yellow",

"lime",

"coral",

"palegreen",

"silver",

"gold",

"red")

delay = .5// seconds

link = 0

vlink = 0

function linkDance() {

link = (link+1)%colors.length

vlink = (vlink+1)%colors.length

document.linkColor = colors[link]

document.vlinkColor = colors[vlink]

setTimeout("linkDance()",delay*1000)

}

linkDance()

// End -->

</script>

看看这个代码是不是你要的

<script

type="text/javascript">

function

colors(color){

var

str=color.innerHTML

var

kk=str.replace(/变色/,

"<span

style='color:#FF0000'>变色</span>")

color.innerHTML=kk

}

</script>

<div

id="test">

测试文字变色

</div>

<a

href="javascript:colors(test)">innerHTML内容</a>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11506954.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存