Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery的两个版本->;2文件。为什么?_Javascript_Jquery_Dom - Fatal编程技术网

Javascript jQuery的两个版本->;2文件。为什么?

Javascript jQuery的两个版本->;2文件。为什么?,javascript,jquery,dom,Javascript,Jquery,Dom,我有一个小页面: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <script type="text/javascript" src="jquery-1.4.2.js"></script&g

我有一个小页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title></title>
  <script type="text/javascript" src="jquery-1.4.2.js"></script>
  <script type="text/javascript" src="temp.js"></script>
</head>
<body>
<p>foo</p>
<p>bar</p>
</body>
</html>

酒吧

我正在尝试加载两个不同版本的jQuery:

// temp.js
jQueryScriptOutputted = false;
initJQuery = function() {

  //if the jQuery object isn't available
  if (typeof(myjQuery) == 'undefined') {

    if (!jQueryScriptOutputted) {
      //only output the script once..
      jQueryScriptOutputted = true;

      //output the script (load it from google api)
      document.write("<script type=\"text/javascript\" src=\"jquery-1.6.4.js\"></script>");
      document.write("<script type=\"text/javascript\">var myjQuery = $.noConflict(true);</script>");
    }
    setTimeout("initJQuery()", 50);
  } else {
    myjQuery(function() {
      // Check jQuery versions
      console.log('myjQuery version = ' + myjQuery().jquery);
      console.log('$ version = ' + $().jquery);
      console.log('jQuery version = ' + jQuery().jquery);

      // Get the data of the actual poll
      document.write("Where is foo and bar?!?");
    });
  }

}
initJQuery();
//temp.js
jQueryScriptOutputted=false;
initJQuery=函数(){
//如果jQuery对象不可用
if(typeof(myjQuery)=“未定义”){
如果(!jqueryscriptoutput){
//仅输出脚本一次。。
jQueryScriptOutputted=true;
//输出脚本(从google api加载)
文件。填写(“”);
write(“var myjQuery=$.noConflict(true);”;
}
setTimeout(“initJQuery()”,50);
}否则{
myjQuery(函数(){
//检查jQuery版本
log('myjqueryversion='+myjQuery().jquery);
log('$version='+$().jquery);
log('jqueryversion='+jQuery().jQuery);
//获取实际投票的数据
文件。写下(“foo和bar在哪里?!”);
});
}
}
initJQuery();

但这似乎加载了两个不同的文档。我的意思是,当你打开页面时,段落会丢失。怎么会这样

只能加载一个版本或另一个版本。
换句话说,页面上只安装了一个jquery库。

问题是您正在将
标记写入文档,而不是

请看这些

本教程介绍了如何真正做好这项工作


希望这有帮助。

调用
文档。加载页面后写入
将用
文档。写入
参数覆盖整个页面。考虑使用一些类似于<代码> $()、AppEnt/<代码>或<代码> $()、HTML < /C> >更改标记。< /P>
i、 e

myjQuery(函数(){
$('body')。追加(foo和bar在哪里?

); });
第一个问题:你为什么要这么做?
myjQuery(function() {
      $('body').append("<p>Where is foo and bar?!?</p>");
    });