点击按钮实现内容颜色的改变
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" >
function changeColor(){
var red=Math.ceil(Math.random()*255);
var green=Math.ceil(Math.random()*255);
var blue=Math.ceil(Math.random()*255);
var color="#"+red.toString(16)+green.toString(16)+blue.toString(16);
document.getElementById("content").style.color=color;
document.getElementById("content").style.fontWeight="bold";
}
</script>
</head>
<body>
<p id="content">我要变换颜色!</p>
<input type="button" value="变换颜色" onclick="changeColor()"/>
</body>
</html>

浙公网安备 33010602011771号