如果你是在学习JS、遇到了各种问题,那么你一定要来这个企鹅裙,前面前面是二九六,中间是五九一,最后面就是二九0,来这里可以得到专人解答,期待你的加入!!!
<div id="txt">我是要改变的文字</div>
<script>
//首先咱们找到要改变的文字
var txt = document.getElementById("txt")
//然后设置一个标记flag
var flag = true
//然后点击这个div或者按钮
txt.onclick = function(){
//改变里面文字颜色
if(flag){
this.style.color = "red"
flag = false
}else{
this.style.color = "#000"
flag = true
}
}
</script>
用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>