- 爱易网页
-
JavaSript
- javaScript使th变色有关问题
日期:2014-05-16 浏览次数:20486 次
javaScript使th变色问题
我想通过点一个BUTTON后,使页面上一个TH变色.下面是我的代码.望知道的朋友不吝赐教,谢谢!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<script language= "javaScript ">
function changecolor(a)
{
if (document.frmbody.testarea.value== " ")
{
a.style.backgroundColor = "red ";
}else
a.style.backgroundColor = " "
}
</script>
</HEAD>
<BODY>
<form name= "frmbody ">
<table>
<tr>
<th name= "th " > Test </th>
<th>
<input type= "textarea " name= "testarea "> </input>
</th>
</tr>
<tr>
<th>
<inputtype= "button "name= "btnReg "value= "Submit "
onclick=changecolor(th)> </input>
</th>
</tr>
</table>
</form>
</BODY>
</HTML>
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<script language= "javaScript ">
function changecolor(a)
{
if (document.frmbody.testarea.value== " ")
{
a.style.backgroundColor = "red ";
}else
a.style.backgroundColor = "white "
}
</script>
</HEAD>
<BODY>
<form name= "frmbody ">
<table>
<tr>
<th id= "th1 " > Test </th>
<th>
<input type= "input " name= "testarea "> </input>
</th>
</tr>
<tr>
<th>
<input type= "button " name= "btnReg " value= "Submit "
onclick=changecolor(document.getElementById( "th1 "))> </input>
</th>
</tr>
</table>
</form>