java怎么定义全局函数,在JavaScript函数中定义全局变量

是否可以在JavaScript函数中定义全局变量?

我想在其他函数中使用 trailimage 变量(在 makeObj 函数中声明) .

var offsetfrommouse = [10, -20];

var displayduration = 0;

var obj_selected = 0;

function makeObj(address) {

**var trailimage = [address, 50, 50];**

document.write(''%20+%20trailimage%5B0%5D%20+%20'');

obj_selected = 1;

}

function truebody() {

return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;

}

function hidetrail() {

var x = document.getElementById("trailimageid").style;

x.visibility = "hidden";

document.onmousemove = "";

}

function followmouse(e) {

var xcoord = offsetfrommouse[0];

var ycoord = offsetfrommouse[1];

var x = document.getElementById("trailimageid").style;

if (typeof e != "undefined") {

xcoord += e.pageX;

ycoord += e.pageY;

}

else if (typeof window.event != "undefined") {

xcoord += truebody().scrollLeft + event.clientX;

ycoord += truebody().scrollTop + event.clientY;

}

var docwidth = 1395;

var docheight = 676;

if (xcoord + trailimage[1] + 3 > docwidth || ycoord + trailimage[2] > docheight) {

x.display = "none";

alert("inja");

}

else

x.display = "";

x.left = xcoord + "px";

x.top = ycoord + "px";

}

if (obj_selected = 1) {

alert("obj_selected = true");

document.onmousemove = followmouse;

if (displayduration > 0)

setTimeout("hidetrail()", displayduration * 1000);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值