相关疑难解决方法(0)

在JavaScript函数中定义全局变量

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <script type="text/javascript">
            var offsetfrommouse = [10, -20];
            var displayduration = 0;
            var obj_selected = 0;
            function makeObj(address) {
                **var trailimage = [address, 50, 50];**
                document.write('<img id="trailimageid" src="' + trailimage[0] + '" border="0"  style=" position: absolute; visibility:visible; left: 0px; top: 0px; width: ' + trailimage[1] + 'px; height: ' + trailimage[2] + 'px">');
                obj_selected = 1;
            }

            function truebody() {
                return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? …
Run Code Online (Sandbox Code Playgroud)

javascript variables scope declaration function

479
推荐指数
10
解决办法
97万
查看次数

287
推荐指数
5
解决办法
26万
查看次数

标签 统计

javascript ×2

declaration ×1

function ×1

scope ×1

variables ×1