这可能只是一个愚蠢的问题,使用jQuery我们都知道很棒的
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/popup.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"> </script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.1.js"></script>
<script type="text/javascript" src="Scripts/popup.js"></script>
</head>
<script>
$(document).ready(function() {
statcode(); //getting it from popup.js
});
</script>
这是我的popup.js:
"use strict";
/*jslint browser:true */
/*global $,jQuery,alert*/
function closeme() {
$("#lbox").fadeOut("slow");
$("#bg").fadeOut("slow");
$(".listboxdatabank").css("visibility", "visible");
}
function statcode() {
var myheight, mywidth, windowWidth, windowHeight, objheight, objwidth, posx, posy;
myheight = $(document).height();
mywidth = $(document).width();
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
objheight = $("#lbox").height();
objwidth = $("#lbox").width();
posx = (windowWidth / 2) - (objwidth / 2);
posy = (windowHeight / 2) - (objheight / 2);
$(".listboxdatabank").css("visibility", "hidden");
$("#bg").css({"width" : mywidth, "height" : myheight});
$("#lbox").css({"left" : posx, "top" : posy});
$("#lbox").fadeIn("slow");
$("#bg").fadeIn("slow");
$("#bg").fadeTo('slow', 0.5);
}
但是当我正在运行它时,给予它 ReferenceError:未定义statcode
答案 0 :(得分:-1)
或尝试这样的事情 -
$( window ).load(function() {
statcode();
});
这将确保在加载外部资源时调用该函数