javascript出现脚本错误 提示函数未定义
<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"><metaname="Generator"content=...
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/script">
function my(color)
{
var table=document.getElemById("colorTable");
table.bgcolor=color;
}
</script>
</head>
<body>
<h3>选取颜色</h3>
<table border="1px">
<tr height="24px">
<td bgcolor="red" width="24px" onclick="my('red')"></td>
<td bgcolor="orange" width="24px" onclick="my('orange')"></td>
<td bgcolor="yellow" width="24px" onclick="my('yellow')"></td>
<td bgcolor="green" width="24px" onclick="my('green')"></td>
<td bgcolor="black" width="24px" onclick="my('black')"></td>
<td bgcolor="blue" width="24px" onclick="my('blue')"></td>
<td bgcolor="purple" width="24px" onclick="my('purple')"></td>
</tr>
</table>
<table id="colorTable" border="1px" height="168px" width="168px">
<tr>
<td></td>
</tr>
</table>
</body>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/script">
function my(color)
{
var table=document.getElemById("colorTable");
table.bgcolor=color;
}
</script>
</head>
<body>
<h3>选取颜色</h3>
<table border="1px">
<tr height="24px">
<td bgcolor="red" width="24px" onclick="my('red')"></td>
<td bgcolor="orange" width="24px" onclick="my('orange')"></td>
<td bgcolor="yellow" width="24px" onclick="my('yellow')"></td>
<td bgcolor="green" width="24px" onclick="my('green')"></td>
<td bgcolor="black" width="24px" onclick="my('black')"></td>
<td bgcolor="blue" width="24px" onclick="my('blue')"></td>
<td bgcolor="purple" width="24px" onclick="my('purple')"></td>
</tr>
</table>
<table id="colorTable" border="1px" height="168px" width="168px">
<tr>
<td></td>
</tr>
</table>
</body>
</html> 展开
1个回答
展开全部
你的Javascript程序我帮你改好了,你看看吧
主要改了type="text/javascript"和my函数中的两个语句,另外,把选择颜色table中的black改成了cyan,其它都没变.
完整的html代码如下
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/javascript">
function my(color)
{
var table=document.getElementById("colorTable");
table.style.backgroundColor=color;
}
</script>
</head>
<body>
<h3>选取颜色</h3>
<table border="1px">
<tr height="24px">
<td bgcolor="red" width="24px" onclick="my('red')"></td>
<td bgcolor="orange" width="24px" onclick="my('orange')"></td>
<td bgcolor="yellow" width="24px" onclick="my('yellow')"></td>
<td bgcolor="green" width="24px" onclick="my('green')"></td>
<td bgcolor="cyan" width="24px" onclick="my('cyan')"></td>
<td bgcolor="blue" width="24px" onclick="my('blue')"></td>
<td bgcolor="purple" width="24px" onclick="my('purple')"></td>
</tr>
</table>
<table id="colorTable" border="1px" height="168px" width="168px">
<tr>
<td></td>
</tr>
</table>
</body>
</html>
运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询