[js动态加载jquery文件同时执行jquery函数的例子]js动态加载jquery文件同时执行jquery函数的例子

时间:2020-09-24  来源:jquery  阅读:
 代码如下






无标题文档
 

<script type="text/javascript"> 

init();
 
function init()
{
 //加载package.js文件,设置script的id为yy
 ajaxPage("yy","js/v6/jquery-1.8.0.min.js");
 //此方法为package.js里面的方法,此处执行方法成功
 jQuery(document).ready(function() {  
  var a = $("#floatbox").offset();  
  $(window).scroll(function() {  
   var b = $(window).scrollTop();  
   if (b > a.top) {
      if((b + 0 + 0) < document.body.parentNode.scrollHeight) 
      $("#floatdiv").addClass("fixed");  
      else
      $("#floatdiv").addClass("fixed2");
   } else {  
    $("#floatdiv").removeClass("fixed"); 
    $("#floatdiv").removeClass("fixed2");
   }  
  });  
 });  
}
function ajaxPage(sId,url)
{
 var oXmlHttp = getHttpRequest();
 oXmlHttp.onreadystatechange = function()
 {
  //4代表数据发送完毕
  if ( oXmlHttp.readyState == 4 )
  {
   //0为访问的本地,200代表访问服务器成功,304代表没做修改访问的是缓存
   if(oXmlHttp.status == 200 || oXmlHttp.status == 0 || oXmlHttp.status == 304)
   {
    includeJS(sId,oXmlHttp.responseText);
   }
   else
   {
   }
  }
 }
 oXmlHttp.open("GET",url,false);//true为异步加载(即在发送ajax的同时可运行其他代码)false为//同步加载(加载的同时不能执行其他代码);
 oXmlHttp.send(null);
}

function getHttpRequest()
{
 if(window.ActiveXObject)//IE
 {
  return new ActiveXObject("MsXml2.XmlHttp");
 }
 else if(window.XMLHttpRequest)//其他
 {
  return new XMLHttpRequest();
 }
}
function includeJS(sId,source)
{
 if((source != null)&&(!document.getElementById(sId)))
 {
  var myHead = document.getElementsByTagName("HEAD").item(0);
  var myScript = document.createElement( "script" );
  myScript.language = "javascript";
  myScript.type = "text/javascript";
  myScript.id = sId;
  try{
   myScript.appendChild(document.createTextNode(source));
  }
  catch (ex){
   myScript.text = source;
  }
  myHead.appendChild( myScript );
 }
}
  
 
</script>




         
         这里是需要固定的内容
          这里是需要固定的内容
          这里是需要固定的内容
          这里是需要固定的内容
         
         

 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 



[js动态加载jquery文件同时执行jquery函数的例子]js动态加载jquery文件同时执行jquery函数的例子

http://m.bbyears.com/wangyezhizuo/100594.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新