假设我具有以下结构,仅是一个示例:
(function number1( $ ) {
$.fn.abcd = function( options ) {
heyyou.find(".123").css({});
heyyou.find(".456").css({});
var delay = 1000;
var site = "http://url";
setTimeout(function(){ window.location.href = site; },delay);}
$("#button").on('click', function(){ window.location.href = site;});
return this;
}( jQuery ));
我认为我需要做的是这样的:
//part1
(function number1( $ ) {
$.fn.abcd = function( options ) {
heyyou.find(".123").css({});
heyyou.find(".456").css({});
return this;
}( jQuery ));
//part2
(function number1( $ ) {
$.fn.abcd = function( options ) {
var delay = 1000;
var site = "http://url";
setTimeout(function(){ window.location.href = site; },delay);}
$("#button").on('click', function(){ window.location.href = site;});
return this;
}( jQuery ));
What I'm trying to achieve here is:
"part1" is going to be inside a js file that's going to be placed inside the header. "part2" is a function that I need to call from a <script></script>
later on the DOM.
The thing is that both parts are using the same main function, one is continuing the other.
例如:
<script src="part1.js"></script>
<body>
<script>//part2</script>
<button id="button">Do something</button>
</body>
So basically I want the function to start in the js file, then I'll finish it from another part. I'm not sure how to explain this, it's just that I need the var site
to be called separately, as I'm going to use the same script for different pages, I need each page to call for the var site
with a different value.
基本上,这是一个重定向脚本,因此我不能对每个页面使用相同的重定向URL。
您可以创建两个单独的函数,将它们链接起来,并使用全局变量在它们之间传递数据。