主页面
2个Iframe<body id="main" >
    <iframe src="IframeHead.aspx" class="IframeHead"></iframe>
    <br />
    <iframe name="frameBody" src="IframeBody.aspx" class="IframeBody" marginwidth="0" marginheight="0" id="newFrameBody"></iframe>   
</body>
想要加载的JS,在一个单独的JS文件里面 //改变样式
     function changeStyle()
     {
        var len=document.getElementsByName("tasks");
        for(var i=0;i<len.length;i++)
        {
        var my=document.getElementById(len[i].id).id;
        var pid=document.getElementById(my).parentNode.id;
        var npid=document.getElementById(pid).nextSibling.id;
        var cid="";
        $("#"+npid).children("div").each(function(){
            cid+=this.id;
    });
        if(len[i].checked)
        {
            document.getElementById(cid).className="delLine"; 
              
        }else
        {
      document.getElementById(cid).className="";
        }
        }
      }
请问我应该怎么调用?

解决方案 »

  1.   

    IframeHead.aspx,IframeBody.aspx中引用该js文件
      

  2.   

    是的我引用了, 但是我写onload时间的时候没有作用,在写onclick的时候有用,请问怎么解决?
      

  3.   

    <iframe name="frameBody"  onload="changestyle()"
      

  4.   

    前面有点错误,应该是这样的!
    如果js是设置IframeBody.aspx页面的,
    又如果js是在IframeBody.aspx页面引用,则在IframeBody.aspx页面的Page_Load中这样调用:
    if (!IsPostBack)
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "changeStyle()", true);试试!
      

  5.   

    这应该不会,你可能js有误!
    做了个简单例子:
    IframeBody.aspx页面的html代码:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>    <script type="text/javascript">
            function changeStyle() {
                document.getElementById("div1").className = "delLine";
            }
        </script>    <style type="text/css">
            .delLine
            {
                background-color: #ff0000;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="div1" style="height: 100px; width: 100px;">
        </div>
        </form>
    </body>
    </html>
    后台c#代码:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "changeStyle()", true);
            }
        }
    直接运行IframeBody.aspx页面,你可以看到div设置成红色!
      

  6.   


     //改变样式
         function changeStyle()
         {
            var len=document.getElementsByName("tasks");
            for(var i=0;i<len.length;i++)
            {
            var my=document.getElementById(len[i].id).id;
            var pid=document.getElementById(my).parentNode.id;
            var npid=document.getElementById(pid).nextSibling.id;
            var cid="";
            $("#"+npid).children("div").each(function(){
                cid+=this.id;
        });
            if(len[i].checked)
            {
                document.getElementById(cid).className="delLine"; 
                  
            }else
            {
          document.getElementById(cid).className="";
            }
            }
          }这个是我的JS,我也页面也都是JSON 出来的,请问为什么,我要是写成onclick就有效..