請高手解答!謝謝!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>math實(shí)例-字體顏色更改</title>
<script type="text/javascript">
function change(){
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("me").style.color=color;
//document.getElementsByTagName(P)[0].style.color=color;
}
</script>
</head>
<body>
<p id="me">我要改變顏色!</p>
<input type="button" value="更改字體顏色" onclick="change()"/>
</body>
</html>
畫下劃線的兩句,為什么第一句可以正常運(yùn)行,第二句就不能正常運(yùn)行,錯(cuò)在哪呢?
2016-12-22
P加“”,試試~~
2016-12-22
我一開始以為代碼有什么問題 看底下回答 注釋掉了 ?額 ?扶額。。。
2016-12-22
document.getElementById("me").style.color=color;
//document.getElementsByTagName(P)[0].style.color=color;
第二句你在前面劃了兩斜杠,這種是代表注釋啊,自然運(yùn)行不了啊,把他刪了試試