以下這段代碼是w3c的方法,沒有問題。鄙人根據(jù)所學(xué)知識,也寫了段代碼。感覺道理上是可以執(zhí)行的,但為啥就不行呢?
<html>
<body>
<script>
function?ChangeBackground()
{document.body.style.backgroundColor="lavender";}
</script>
<input?type="button"?onclick="ChangeBackground()"
value="Change?background?color"?/>
</body>
</html>
以下是鄙人寫的代碼,為什么就執(zhí)行不了呢?
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>無標(biāo)題文檔</title>
<script>
function?abc()
{
?var?a=document.getElementsByTagName('body');
?a.style.color='red';
?}
</script>
</head>
<form>
<input?type="button"?value="點(diǎn)擊按鈕改變背景顏色"?onclick="abc()"/>
</form>
</body>
</html>
javascript按下按鈕改變背景顏色,為什么我寫的就不行呢?
Tang小溪
2016-05-20 14:47:19