Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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 使用Polymer通过HTML导入包含jQuery,在Safari和Firefox中不起作用_Javascript_Jquery_Polymer_Web Component - Fatal编程技术网

Javascript 使用Polymer通过HTML导入包含jQuery,在Safari和Firefox中不起作用

Javascript 使用Polymer通过HTML导入包含jQuery,在Safari和Firefox中不起作用,javascript,jquery,polymer,web-component,Javascript,Jquery,Polymer,Web Component,我试图通过HTML导入将jQuery包含在主页中,但它只在Chrome中起作用。Safari和Firefox都在主页JavaScript代码的第一行抛出了一条“ReferenceError:$IsNotDefined”消息。页面上的JavaScript代码似乎是在将jQuery对象加载到Safari或Firefox之前执行的。我使用的是Polymer(0.4)和jQuery(2.1.1)的最新版本。下面是一个简单的例子: jquery.html <script src="https://c

我试图通过HTML导入将jQuery包含在主页中,但它只在Chrome中起作用。Safari和Firefox都在主页JavaScript代码的第一行抛出了一条“ReferenceError:$IsNotDefined”消息。页面上的JavaScript代码似乎是在将jQuery对象加载到Safari或Firefox之前执行的。我使用的是Polymer(0.4)和jQuery(2.1.1)的最新版本。下面是一个简单的例子:

jquery.html

<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>

main.html

<!DOCTYPE html>
<html>
<head>
    <title>Import jQuery</title>
    <script src="http://www.polymer-project.org/platform.js"></script>
    <link rel="import" href="jquery.html">
</head>
<body>
<script>
$(document).ready(function() {
    console.log("Hello World!");
});
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <title>Import jQuery</title>
    <script src="http://www.polymer-project.org/platform.js"></script>
    <link rel="import" href="jquery.html">
</head>
<body>
    <link rel="import" href="code.html">
</body>

导入jQuery
$(文档).ready(函数(){
log(“你好,世界!”);
});

我错过了什么明显的东西吗?谢谢

现在Safari和Firefox都不支持HTMLImports。相反,
platform.js
使用Ajax请求来填充该特性

如果没有本机浏览器支持,就无法让您的
标记等待导入完成加载。因此,要支持多边形填充,您必须等待
HTMLImportsLoaded
事件触发(或将所有依赖代码放在导入后面)

因此,要么:

<!DOCTYPE html>
<html>
<head>
    <title>Import jQuery</title>
    <script src="http://www.polymer-project.org/platform.js"></script>
    <link rel="import" href="jquery.html">
</head>
<body>
<script>
  addEventListener('HTMLImportsLoaded', function() {
    $(document).ready(function() {
      console.log("Hello World!");
    });
  });
</script>

</body>
</html>

导入jQuery
addEventListener('HTMLImportsLoaded',函数(){
$(文档).ready(函数(){
log(“你好,世界!”);
});
});

code.html

<script>
  $(document).ready(function() {
    console.log("Hello World!");
  });
</script>

$(文档).ready(函数(){
log(“你好,世界!”);
});
main.html

<!DOCTYPE html>
<html>
<head>
    <title>Import jQuery</title>
    <script src="http://www.polymer-project.org/platform.js"></script>
    <link rel="import" href="jquery.html">
</head>
<body>
<script>
$(document).ready(function() {
    console.log("Hello World!");
});
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <title>Import jQuery</title>
    <script src="http://www.polymer-project.org/platform.js"></script>
    <link rel="import" href="jquery.html">
</head>
<body>
    <link rel="import" href="code.html">
</body>

导入jQuery