Heim  >  Artikel  >  Web-Frontend  >  javaScript 页面自动加载事件详解_javascript技巧

javaScript 页面自动加载事件详解_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:00:511158Durchsuche
方法1:
复制代码 代码如下:

 Window.onload=function(){
   Var name=document.getElementById(“name”).val();//加载HTML,并且加载外部所有所有的引用文件(图片,css样式,js等)
}

方法2:需要引入Jquery的 .js文件
复制代码 代码如下:

$(document).ready(function(){
         alert("JQuery的第一个入门案例");//加载HTML,不需等待,立即加载
});

方法3: ( 等同于方法2 )
复制代码 代码如下:

jQuery(function (){
       if($("input[name='message']").val()!="")
           alert($("input[name='message']").attr("value"));
});

方法4 :(等同于上)
复制代码 代码如下:

$(function (){
    alert("JQuery 页面自动加载时执行 1 ....");
 });

方法5-1:window.onload事件的加载(页面加载时同时加载多个函数...)
复制代码 代码如下:


   
  

<script><BR> function1(){<BR> }<BR>function2(){<BR>}<BR>function3(){<BR>}<BR></script>

方法5-2:window.onload事件的加载(页面加载时同时加载多个函数...)
复制代码 代码如下:


   
   

<script><BR> function1(){<BR> }<BR> function2(){<BR> }<BR> function3(){<BR> }<BR> window.onload=function(){<BR> function1();<BR> function2();<BR> function3();<BR> }<BR></script>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn