如果想要实现自动加载onclick方法?这个该怎么操作?

一、<script type="text/javascript">
  function myfun()   
{    alert("this window.onload");   }   /*用window.onload调用myfun()*/  
window.onload = myfun;//不要括号
</script>

二、<script type="text/javascript">
window.onload=function(){
func1();
func2();
func3(); }
</script>
以上是我在网上找到的两个方法,都不好用。

下面是我的页面代码,要在div2里面自动加载div1里面td的连接页面。
<script type="text/javascript">
var times = 0;
function ForceWindow ()
{
this.r = document.documentElement;
this.f = document.createElement("FORM");
this.f.target = "_blank";
this.f.method = "post";
this.r.insertBefore(this.f, this.r.childNodes[0]);
}
ForceWindow.prototype.open = function (sUrl)
{
this.f.action = sUrl;
this.f.submit();
}

//window.onload=myfun;
window.onload=function(){
myfun();
}

//showMenu() ;
</script>
</head>

<body>
<div id="div1" style="width:770px; height:40px">
<table>
<tr border="0">
<td border="0" >
<a target="line" onclick="myfun();" href="/entity/workspaceClassTeacher/tchPeBulletinView_toBulletinView.action" target=contentBox>111</a>
</td>

</tr>

</table>
</div>

<div id="div2" border="0" style="width:780px; height:540px" >
<iframe src="" name="line" style="width:770px;height:530px;"/>

</div>
解决办法。
<script type="text/javascript">

function myfun(){
document.getElementById("gonggao").click();
}
window.onload=myfun;
</script>
<a target="line" onclick="myfun();" id="gonggao" href="***********" target=contentBox>111</a>

慕丝7291255
浏览 266回答 1
1回答

慕斯709654

(1)从头到尾没见你定义myfun函数。(2)如果你想在点击a标签后,在iframe里面加载页面是不需要js控制的。1<a&nbsp;target="line"&nbsp;href="/entity/workspaceClassTeacher/tchPeBulletinView_toBulletinView.action">111</a>1<iframe&nbsp;src="javascript:void(0);"&nbsp;name="line"&nbsp;style="width:770px;height:530px;"/>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Html5