Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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/2/image-processing/2.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
从其他页面运行jQuery_Jquery - Fatal编程技术网

从其他页面运行jQuery

从其他页面运行jQuery,jquery,Jquery,因此,我有以下文件a.html,b.html,c.js。我希望能够实现以下目标: 当我点击a.html上的链接时,被重定向到b.html,只有在b.html完全加载后,我的c.js才会运行并引用b.html的元素。例如,打开一个面板。在b.html中: <script> $(document).ready(function(){ ... }); </script> $(文档).ready(函数(){…}); 当我点击a.html上的链接时,会被重定向到b.h

因此,我有以下文件
a.html
b.html
c.js
。我希望能够实现以下目标:

当我点击
a.html
上的链接时,被重定向到
b.html
,只有在
b.html
完全加载后,我的
c.js
才会运行并引用
b.html
的元素。例如,打开一个面板。

在b.html中:

<script>
  $(document).ready(function(){  ...  });
</script>

$(文档).ready(函数(){…});
当我点击a.html上的链接时,会被重定向到b.html

这只是一个标准链接,与问题有点无关

只有在完全加载b.html之后,我的c.js才会运行并生成 对b.html元素的引用

所以你有一个c.js可以“运行”。一个简单的解决方案是编辑c.js并将其包装

jQuery(document).ready(function () {

    // original contents of c.js go here

});
在b.html中,将jQuery和c.js包含在文档的头部(按顺序)

但是,您可以将c.js脚本作为主体中的最后一个标记

<body>

   ... some contents here ...

    <script type="text/javascript" src="c.js">
</body>

... 这里有些内容。。。

如果您正在等待页面完全加载,您可能希望将其包装在
$(窗口)中。load()

在我的iPad上,我点击
?123
键,然后长按撇号,这会显示包括backtick在内的4个备用字符。很好:)谢谢Keith!不过,iPhone并不是最有用的代码编辑工具!当你身边没有iPad时,感觉真好:)