
网页调用js,为什么老是说网页上有错误
//JScript文件如下:vardefaultNewProductTabId=0;functionchangeNewProductTab(id){if(id!=defa...
// JScript 文件
如下:
var defaultNewProductTabId=0;
function changeNewProductTab(id)
{
if(id!=defaultNewProductTabId)
{
document.getElementById("newproduct_tab_"+id).className="default_tab1";
document.getElementById("newproduct_content_"+id).style.display="";
document.getElementById("newproduct_tab_"+defaultNewProductTabId).className="default_tab2";
document.getElementById("newproduct_content_"+defaultNewProductTabId).style.display="none";
defaultNewProductTabId=id;
}
}
错误说是缺少‘{’,代码处:0
就是定义对象var defaultNewProductTabId=0;
这个地方!我要是把这个定义在函数体内,就不会有网页上错误的提示!但是不能有我要的js效果--要道到的效果是:鼠标指在某处就显示此处要的结果!
可是定义在函数外效果有就是出现网页上错误,烦死人了!上面定义方式没有错吧
求解 展开
如下:
var defaultNewProductTabId=0;
function changeNewProductTab(id)
{
if(id!=defaultNewProductTabId)
{
document.getElementById("newproduct_tab_"+id).className="default_tab1";
document.getElementById("newproduct_content_"+id).style.display="";
document.getElementById("newproduct_tab_"+defaultNewProductTabId).className="default_tab2";
document.getElementById("newproduct_content_"+defaultNewProductTabId).style.display="none";
defaultNewProductTabId=id;
}
}
错误说是缺少‘{’,代码处:0
就是定义对象var defaultNewProductTabId=0;
这个地方!我要是把这个定义在函数体内,就不会有网页上错误的提示!但是不能有我要的js效果--要道到的效果是:鼠标指在某处就显示此处要的结果!
可是定义在函数外效果有就是出现网页上错误,烦死人了!上面定义方式没有错吧
求解 展开
展开全部
<!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>无标题文档</title>
<style type="text/css">
.default_tab1
{
color: red;
}
.default_tab2
{
color: blue;
}
td{
cursor:hand;
}
</style>
<script type="text/javascript">
var defaultNewProductTabId=0;
function changeNewProductTab(id)
{
if(id!=defaultNewProductTabId)
{
document.getElementById("newproduct_tab_"+id).className="default_tab1";
document.getElementById("newproduct_content_"+id).style.display="";
document.getElementById("newproduct_tab_"+defaultNewProductTabId).className="default_tab2";
document.getElementById("newproduct_content_"+defaultNewProductTabId).style.display="none";
defaultNewProductTabId=id;
}
}
</script>
</head>
<body>
<table border="1" style="border-collapse:collapse" width="235px">
<tr>
<td id="newproduct_tab_0" class="default_tab1" onclick="changeNewProductTab(0)">
one
</td>
<td id="newproduct_tab_1" class="default_tab2" onclick="changeNewProductTab(1)">
two
</td>
<td id="newproduct_tab_2" class="default_tab2" onclick="changeNewProductTab(2)">
three
</td>
</tr>
</table>
<label id="newproduct_content_0">
111111</label>
<label id="newproduct_content_1" style="display:none">
222222</label>
<label id="newproduct_content_2" style="display:none">
333333</label>
</body>
</html>
测试了下没啥问题,查看下是否其他代码影响.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.default_tab1
{
color: red;
}
.default_tab2
{
color: blue;
}
td{
cursor:hand;
}
</style>
<script type="text/javascript">
var defaultNewProductTabId=0;
function changeNewProductTab(id)
{
if(id!=defaultNewProductTabId)
{
document.getElementById("newproduct_tab_"+id).className="default_tab1";
document.getElementById("newproduct_content_"+id).style.display="";
document.getElementById("newproduct_tab_"+defaultNewProductTabId).className="default_tab2";
document.getElementById("newproduct_content_"+defaultNewProductTabId).style.display="none";
defaultNewProductTabId=id;
}
}
</script>
</head>
<body>
<table border="1" style="border-collapse:collapse" width="235px">
<tr>
<td id="newproduct_tab_0" class="default_tab1" onclick="changeNewProductTab(0)">
one
</td>
<td id="newproduct_tab_1" class="default_tab2" onclick="changeNewProductTab(1)">
two
</td>
<td id="newproduct_tab_2" class="default_tab2" onclick="changeNewProductTab(2)">
three
</td>
</tr>
</table>
<label id="newproduct_content_0">
111111</label>
<label id="newproduct_content_1" style="display:none">
222222</label>
<label id="newproduct_content_2" style="display:none">
333333</label>
</body>
</html>
测试了下没啥问题,查看下是否其他代码影响.
本回答被提问者采纳
展开全部
这里没有问题,不是这里出的错,JS的错误提示准确率相当低!
展开全部
没看出问题所在,估计是别的地方的问题
展开全部
考虑一下和其他js代码或文件的影响。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询