IE好像能用function window.onload(),但是,换成chome就不行了,怎么回事啊,出了这个,还有其他的方法吗?

解决方案 »

  1.   


    window.onload=function() {
    alert("加载完毕了");
    }
      

  2.   


    这样写后也没有弹出"string"啊!
      

  3.   

    <head runat="server">
        <title></title>
        <script type="text/javascript">
            window.onload = function() { alert('what?'); }
        </script>
    </head>得写在<script />区块内。或者把
    <script type="text/javascript">
    alert('what?');
    </script>
    放在</body>结束前也行。如果是asp.net,后台代码里写:
    Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('what?');", true);
      

  4.   

    2楼正确,如果再弹不出来那就是你的HTML页面编码有问题或者其他的语法问题,试试纯英文的:<script type="text/javascript">
    window.onload = function() {
        alert("page loaded!");
    };
    </script>
    我不相信你这次弹不出来!
      

  5.   

    window.onload就OK了。
    ---
    但是,如果要在加载完后执行多个函数的话,就需要如下:
    window.attachEvent('onload',fun1);
    window.attachEvent('onload',fun2);  
    以上是IE版本,FF等版本为使用addEventListener函数
    ---
    如果是JQuery的话,可以用
    $(document).ready(function(){});
    也可以用JQuery的bind来做
      

  6.   

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.3.0.1770, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86" namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" tagprefix="esri" %><!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 runat="server">
    <script type="text/javascript" language="javascript">
       function GetResouceContent()
       {
         var message = 'ActiveType=GetResourceContent';
         
         var context='Page1';
         <%=getResourceContentCallBack %>
         
       }
       
       
       function ShowFieldInfo()
       {
         
         var o = document.getElementById("LayerList");
         var message = 'ActiveType=ShowFieldInfo&EventArg=';
         message += o.value;
         var context = 'Page1';
         <%=ShowFieldInfoCallBack %>
       }
       
    </script>
        <title>NorthAmericaMap</title>
        <link href="css/style1.css" type="text/css" rel="Stylesheet" />
        <style type="text/css">
            .style4
            {            width: 118px;
            }
            .style5
            {
                width: 926px;
            }
            .style6
            {
                height: 53px;
                width: 926px;
            }
            </style>
        <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div>    
            <table border="1" style="width: 100%; height: 598px;">
                <tr>
                    <td class="style6">
                        <esri:Toolbar ID="Toolbar1" runat="server" BuddyControlType="Map" 
                            Group="Toolbar1_Group" Height="50px" ToolbarItemDefaultStyle-BackColor="White" 
                            ToolbarItemDefaultStyle-Font-Names="Arial" 
                            ToolbarItemDefaultStyle-Font-Size="Smaller" 
                            ToolbarItemDisabledStyle-BackColor="White" 
                            ToolbarItemDisabledStyle-Font-Names="Arial" 
                            ToolbarItemDisabledStyle-Font-Size="Smaller" 
                            ToolbarItemDisabledStyle-ForeColor="Gray" 
                            ToolbarItemHoverStyle-BackColor="White" ToolbarItemHoverStyle-Font-Bold="True" 
                            ToolbarItemHoverStyle-Font-Italic="True" 
                            ToolbarItemHoverStyle-Font-Names="Arial" 
                            ToolbarItemHoverStyle-Font-Size="Smaller" 
                            ToolbarItemSelectedStyle-BackColor="White" 
                            ToolbarItemSelectedStyle-Font-Bold="True" 
                            ToolbarItemSelectedStyle-Font-Names="Arial" 
                            ToolbarItemSelectedStyle-Font-Size="Smaller" 
                            WebResourceLocation="/aspnet_client/ESRI/WebADF/" Width="400px">
                            <ToolbarItems>
                                <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomIn.gif" 
                                    HoverImage="esriZoomInU.gif" JavaScriptFile="" Name="MapZoomIn" 
                                    SelectedImage="esriZoomInD.gif" 
                                    ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls" 
                                    ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomIn" 
                                    Text="Zoom In" ToolTip="Zoom In" />
                                <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomOut.gif" 
                                    HoverImage="esriZoomOutU.gif" JavaScriptFile="" Name="MapZoomOut" 
                                    SelectedImage="esriZoomOutD.gif" 
                                    ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls" 
                                    ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomOut" 
                                    Text="Zoom Out" ToolTip="Zoom Out" />
                                <esri:Tool ClientAction="DragImage" DefaultImage="esriPan.gif" 
                                    HoverImage="esriPanU.gif" JavaScriptFile="" Name="MapPan" 
                                    SelectedImage="esriPanD.gif" 
                                    ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls" 
                                    ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapPan" Text="Pan" 
                                    ToolTip="Pan" />
                                <esri:Command ClientAction="" DefaultImage="esriFullExt.gif" 
                                    HoverImage="esriFullExtU.gif" JavaScriptFile="" Name="MapFullExtent" 
                                    SelectedImage="esriFullExtD.gif" 
                                    ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls" 
                                    ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapFullExtent" 
                                    Text="Full Extent" ToolTip="Full Extent" />
                            </ToolbarItems>
                            <BuddyControls>
                                <esri:BuddyControl Name="Map1" />
                            </BuddyControls>
                        </esri:Toolbar>
                        
                    </td>
                    <td class="style4" rowspan="2">
                    <div>
                        <esri:Toc ID="Toc1" runat="server" BuddyControl="Map1" Height="191px" />
                    </div>
                        <asp:Label ID="Label1" runat="server" Text="查询图层:"></asp:Label>
                        <br />
                        <div id="layerListDiv">
                            <asp:DropDownList ID="DropDownList1" runat="Server" Height="16px" Width="153px">                        </asp:DropDownList>                    </div>
                                                  <div id="fieldListDiv">
        </div>
                    </td>
                </tr>
                <tr>
                    <td class="style5">
                        <esri:MapResourceManager ID="MapResourceManager1" runat="server">
                            <ResourceItems>
                                <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;In Memory&quot; DataSourceType=&quot;GraphicsLayer&quot; Identity=&quot;&quot; ResourceDefinition=&quot;&quot; DataSourceShared=&quot;True&quot; /&gt;" 
                                    DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=:transbg=False:displayInToc=True:dynamicTiling=" 
                                    LayerDefinitions="" Name="Selection" />
                                <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;localhost&quot; DataSourceType=&quot;ArcGIS Server Local&quot; Identity=&quot;To set, right-click project and 'Add ArcGIS Identity'&quot; ResourceDefinition=&quot;Layers@NorthAmerica&quot; DataSourceShared=&quot;True&quot; /&gt;" 
                                    DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=White:transbg=True:displayInToc=True:dynamicTiling=" 
                                    LayerDefinitions="" Name="NorthAmericaMap" />
                            </ResourceItems>
                        </esri:MapResourceManager>
                        <esri:Map ID="Map1" runat="server" Height="454px" InitialExtent="Full" 
                            MapResourceManager="MapResourceManager1" Width="922px">
                        </esri:Map>
                    </td>
                </tr>
            </table>
        
        </div>
        <p>
            <esri:ContextMenu ID="ContextMenu1" runat="server" BackColor="White" 
                onitemclicked="ContextMenu1_ItemClicked" />
        </p>
        </form></body>
    <script type="text/javascript" language="javascript">
       function window.onload() 
       {
         GetResouceContent();
       }
       
    </script>
    </html> 源代码这样的,在IE中会执行GetResouceContentv(),
    但是在chome中就不会执行
      

  7.   

    看看jQuery 中的 ready 就会明白了。
      

  8.   

    window.onload() 失效的原因可能是 <body onload="fun()">
      

  9.   

    哈哈,真好使window.onload=function(){
                                //代码内容
                                    }