JavaScript函数从本地计算机运行,但不从服务器运行

时间:2013-05-14 13:33:17

标签: javascript internet-explorer

我正在编写一个脚本,显示/隐藏级联列表,因为从四个下拉菜单中选择了每个选项。例如,当一个人选择一个州时,它会隐藏默认的空城市列表,而是显示该州的相应城市列表。

以下是我的HTML的简化版本:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="mapselector3.js"></script>
        <link rel="stylesheet" type="text/css" href="mapselectorstyles3.css" />
    </head>
    <body onload="reset('selectstate')">
        <div id="wrapper">
        <h1>Device Installation</h1>
        <p>Select a specific printer by location:</p>
        <form name="mapselector">


            <div class="selectholder">
            <label>Select State:</label>

            <!--states list-->
            <select id="stateselector">
                <option class="selectstate" selected="selected" >Select a State</option>
                <option onclick='showCities("mn")'>Minnesota</option>
                <option onclick='showCities("tx")'>Texas</option>
                <option onclick='showCities("ca")'>California</option>
            </select>

            </div>

            <div class="selectholder">
            <label>Select City:</label>

            <!--cities default list-->
            <select id="cityselector">
                <option>City</option>
            </select>


            <!--cities options-->
            <select id="mn" class="hidden">
                <option  class="selectcity" selected="selected">Then a City</option>
                <option onclick='showBuildings("mn-maplewood")'>Maplewood</option>

            </select>


            </div>

            <div class="selectholder">
            <label>Select Building:</label>

            <!--Building default list-->
            <select id="buildingselector">
                <option>Building</option>
            </select>


            <!--MN buildings options-->
            <select id="mn-maplewood" class="hidden">
                <option  class="selectbuilding" selected="selected">Then a Building</option>
                <option onclick='showFloors("mn-maplewood-b224")'>Building 224</option>
                <option onclick='showFloors("mn-maplewood-b220")'>Building 220</option>
                <option onclick='showFloors("mn-maplewood-b223")'>Building 223</option>
            </select>


            </div>

            <div class="selectholder">
            <label>Select Floor:</label>

            <!--Floors default list-->
            <select id="floorselector" name="floorselector">
                <option>Floor</option>
            </select>


            <!--MN-maplewood floors lists-->
            <select id="mn-maplewood-b224" class='hidden'>
                <option  class="selectfloor" selected="selected">Then a Floor</option>
                <option onclick='setButtonPath("states/mncities/maplewoodbuildings/224floors/us-mn-maplewood-b224-floor1.htm")'>Floor 1</option>
                <option onclick='setButtonPath("states/mncities/maplewoodbuildings/224floors/us-mn-maplewood-b224-floor2.htm")'>Floor 2</option>
                <option onclick='setButtonPath("states/mncities/maplewoodbuildings/224floors/us-mn-maplewood-b224-floor3.htm")'>Floor 3</option>
            </select>



            </div>


            <a id="submit" href="mapselector3.htm"><div id="button">Floor Map</div></a>
        </form>
        <div id="test"></div>
        <div id="currentstate"></div>
        <div id="currentcity"></div>
        <div id="currentbuilding"></div>
        <div id="currentfloor"></div>
        </div>
    </body>
</html>

我已经把它减少到一个选项,但我的名单将包括大约25个州,每个州有不同数量的城市,每个城市的建筑物和每个建筑物的楼层。我已经在HTML中生成了所有列表,并使用CSS将它们隐藏在屏幕外,我的JavaScript旨在在单击选项时交换相应的列表。

这是我的脚本的样子:

var currentState = 'cityselector';
var currentCity = 'buildingselector';
var currentBuilding = 'floorselector';

function reset(selector) {
    var reset = document.getElementsByClassName(selector);
    for(i=0; i<reset.length; i++) {
        reset[i].selected = "selected";
    }
}

function hide(element) {
    document.getElementById(element).className = "hidden";
}

function show(element) {
    document.getElementById(element).className = "shown";
}

function showCities(stateName) {
    document.getElementById('test').innerHTML = 'in showCities()';
    //hide the current selections and reset the lists to show "Then a City"
    hide(currentState);
    hide(currentCity);
    hide(currentBuilding);
    reset('selectcity');

    //set the currentState to the value clicked and reset currentCity and currentBuilding to their original defaults
    currentState = stateName;
    currentCity = 'buildingselector';
    currentBuilding = 'floorselector';

    //rebuild the list
    show(stateName);
    show(currentCity);
    show(currentBuilding);
    document.getElementById('currentstate').innerHTML = 'currentState = ' + currentState;
}

function showBuildings(cityName) {
    document.getElementById('test').innerHTML = 'in showBuildings()';
    //hide the current selections and reset the lists to show "Then a Building"
    hide(currentCity);
    hide(currentBuilding);
    reset('selectbuilding');

    //set the currentCity to the value clicked and reset currentBuilding to its' original default
    currentCity = cityName;
    currentBuilding = 'floorselector';

    //rebuild the list
    show(cityName);
    show(currentBuilding);
    document.getElementById('currentbuilding').innerHTML = 'currentBuilding = ' + cityName;
}

function showFloors(building) {
    document.getElementById('test').innerHTML = 'in showFloors()';
    //hide the current selections and reset the lists to show "Then a Floor"
    hide(currentBuilding);
    reset('selectfloor');

    //set the currentBuilding to the value clicked
    currentBuilding = building;

    //rebuild the list
    show(building);
}

function setButtonPath(path) {
    document.getElementById('test').innerHTML = 'in setButtonPath()';
    submitButton = document.getElementById('submit');
    submitButton.href = path;
}

当从我的本地硬盘在IE中运行时,脚本的功能完全符合预期,但当我将文件保存到域中的共享网络文件夹并从那里运行时,脚本无法运行({{除外) 1}}。我尝试用Jquery重写整个事情,并遇到了同样的问题。它可以在Firefox和Chrome中运行,我无法在Firebug中找到任何错误,但我需要在IE中使用它任何想法?

0 个答案:

没有答案