日期:2014-05-16  浏览次数:20384 次

请问我的这个错在哪里(一个JS改变字体颜色)
<head> <title> 变颜色字体 </title>
<script   language= "javascript ">
function   bcolor()
{
var   a=document.yuan.color1.color;
if(a!= "red ")
a= "red ";
}
</script>
</head>
<body>
<form   name= "yuan ">
<id= "color1 "> 袁浩琳
<input   type= "button "   value= "单击 "   onclick= "bcolor() ">

</form>

------解决方案--------------------
<head> <title> 变颜色字体 </title>
<script language= "javascript ">
function bcolor()
{
var a=document.all.color1;
if(a.style.color!= "red ")
a.style.color= "red ";
}
</script>
</head>
<body>
<form name= "yuan ">
<span id= "color1 "> 袁浩琳 </span>
<input type= "button " value= "单击 " onclick= "bcolor() ">

</form>