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

网页中如何更改相关属性?
一个网页中有一个div(叫buyurl),div中有一个iframe(叫ifr),iframe中有一个网页(detail.asp)之中有一个表格table(叫ta1),请问我如何在主网页中用javascript改变这个表格的visiability属性?


我在detail.asp中可以改变那个属性,用如下语句:

document.all.ta1.style.visibility= 'hidden ';

这样表格就隐藏了。我现在想在主页面中改变这个属性,让表格再显示出来却出现了问题,我用如下语句:

document.getElementById( "ifr ").document.all.ta1.style.visibility= 'visible ';

错误提示是:
document.getElementById(...).document.all.ta1.style为空或不是对象,请问为什么?


------解决方案--------------------
top.frames[ "ifr "].document.all.ta1.style
------解决方案--------------------
window.ifr.document.all.ta1.style
------解决方案--------------------
<html>
<head>
<script>
function myFun()
{

var ifr = document.getElementById( "ifr ");
var table = window.ifr.document.getElementById( "table1 ");
if ( table.style.display == " " )
{
table.style.display = "none ";
}
else
{
table.style.display = " ";
}

}
</script>
</head>
<body>

<input type= "button " value= "试验 " onclick= "myFun(); ">
<div>
<iframe id= 'ifr ' src= 'test.htm '>
</div>
</body>
</html>
//////////////////////////////
test.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<table id= "table1 " border= '1 '>
<tr>
<td> dfdfdf </td>
</tr>
</table>
</body>
</html>
我做了一个简单的例子,希望对你有帮助
------解决方案--------------------
<a href= "http://community.csdn.net/Expert/topic/5321/5321996.xml?temp=.5491754 "> http://community.csdn.net/Expert/topic/5321/5321996.xml?temp=.5491754 </a>