<TABLE cellSpacing="0" cellPadding="0" width="99%" border="0" id="BaseTabel6">
<TR>
<TD width="28%">Company name of chinese:</TD>
<TD width="72%" height="25">
<span id="Baselabel2"></span></TD>
</TR>
<TR>
<TD bgColor="#cccccc"></TD>
<TD bgColor="#cccccc" height="1"></TD>
</TR>
</TABLE>我想让当<span id="BaseLabe2"></span>为空字符时不显示表格我写的JS代码为:
with ( document.Form1 )
{
for(int i=0;i<17;i++)
{
var t = document.getElementById('BaseLabel'+i);
if(t.innerText=="")
document.getElementById('BaseTabel'+i).style.display = "none";
}
} 可没有实现我所要的结果,各位大哥,请解答解答,小弟在此谢过!
<TR>
<TD width="28%">Company name of chinese:</TD>
<TD width="72%" height="25">
<span id="Baselabel2"></span></TD>
</TR>
<TR>
<TD bgColor="#cccccc"></TD>
<TD bgColor="#cccccc" height="1"></TD>
</TR>
</TABLE>我想让当<span id="BaseLabe2"></span>为空字符时不显示表格我写的JS代码为:
with ( document.Form1 )
{
for(int i=0;i<17;i++)
{
var t = document.getElementById('BaseLabel'+i);
if(t.innerText=="")
document.getElementById('BaseTabel'+i).style.display = "none";
}
} 可没有实现我所要的结果,各位大哥,请解答解答,小弟在此谢过!
{
for(int i=0;i<17;i++)
{
var t = document.getElementById('BaseLabel'+i);
if(t.innerText=="")
document.getElementById('BaseTabel'+i).style.display = "none";
}
}with里面不应该再用document对象,会引起找不到对象的错误,且Js里只有弱类型,没有int的定义方法
应该是 for(var i=0;i<17;i++)
{
var t = document.getElementById('BaseLabel'+i);
if(t.innerText=="")
document.getElementById('BaseTabel'+i).style.display = "none";
}
<script>
function aaa()
{
for(var i=0;i<17;i++)
{
var t = document.getElementById('BaseLabel'+i);
if(t != null){
alert(t.innerText);
if(t.innerText == '')
document.getElementById('BaseTabel'+i).style.display = "none";
}
}
}
</script>
<body onLoad="aaa()">
<form name="form1">
<TABLE cellSpacing="0" cellPadding="0" width="99%" border="0" id="BaseTabel6">
<TR>
<TD width="28%">Company name of chinese:</TD>
<TD width="72%" height="25">
<span id="Baselabel6"></span></TD>
</TR>
<TR>
<TD bgColor="#cccccc"></TD>
<TD bgColor="#cccccc" height="1"></TD>
</TR>
</TABLE>
</form>
</body>
还有我就是不明白with(document.form1){}这个用法,希望能回答一下,我试了好几次也没成功
1 循环的时候 定义 int i 这里出问题了吧 应该时var i
2 js里的BaseTabel 与 HTML里的 Baselabel 搞错了 吧
正确如下
with (document.Form1)
{
for(var i=0;i<17;i++)
{
var t = document.getElementById('Baselabel'+i);
if (t)
{
if(t.innertText=="")
{
document.getElementById('Baselabel'+i).style.display = "none";
}
}
}
}