脚本

时间:2015-08-10 14:52:32

标签: javascript variables url src

脚本文件和jsfile一起驻留在Apache主页服务器上。 在index.html的head部分我们有

 <script type="text/javascript" src="someurl/jsfile.js"></script/>

在脚本文件中我们通过

引用jsfile
function init_disp() {array_len = jsfile.length...

使用或不使用someurl运行脚本文件会产生&#34;&#39; jsfile&#39;未定义&#34;错误。这里有问题,或者如果服务器软件阻止了脚本,它是通过归零变量来实现的吗?

使用IE11增强保护和64位增强保护,64位Java。 编辑:整个脚本文件(不是我自己的)是这样的:

    addEvent(window,"load",init_disp);
    addEvent(document,"click",show_init);
    // function to add an event listener
    function addEvent(o,e,f) {
    if (o.addEventListener) {
    o.addEventListener(e,f,false);
    return true;
    }
    else if (o.attachEvent) {
    return o.attachEvent("on"+e,f);
    }
    else {
    return false;
    }
    }
    // integer "random()"
    function rand (n)
    {
    return (Math.floor( Math.random ()*n));
    }
    // BEGIN customization settings
    var char_pause = 60; // pause on each character, milliseconds
    var quote_pause = 8000; // pause to show complete quote, milliseconds
    // END customization settings
    var quoteindex;
    var quote,attribution;
    var pos;
    var box;
    var array_len;
    var quote_len,attrib_len;
    var interval = null;
    var busy;
    var cursor_span = "<span class=\"quotefont quotecursor\">";
    var hide_span = "<span class=\"quotefont hidecolor\">"
    var attr_div = "<p></p><div class=\"quotefont attrib\">";

    function init_disp() {
    array_len = jsfile.length;
    box = document.getElementById("quotebox");
    quoteindex = rand(array_len);
    show_init();
    }
    function show_init() {
    busy = false;
    clearInterval(interval);
    quote_array = jsfile[quoteindex].split("\t");
    quote = quote_array[0];
    attribution = quote_array[1];
    quote_len = quote.length;
    attrib_len = attribution.length;
    quoteindex = (quoteindex+1) % array_len;
    pos = 0;
    interval = setInterval('show_quote()',char_pause);
    }
    function show_quote() {
    pos++;
    if(!busy) {
    busy = true;
    if(pos <= quote_len) {
      box.innerHTML = quote.substring(0,pos) +
      cursor_span +
      quote.substring(pos,pos+1) +
      "</span>" +
      hide_span +
      quote.substring(pos+1) +
      "</span>";
    }
    busy = false;
    }
    if(pos > quote_len) {
    pos = 0;
    clearInterval(interval);
    interval = setInterval('show_attr()',char_pause);
    }
    }
    function show_attr() {
    pos++;
    if(!busy) {
    busy = true;
    if(pos <= attrib_len) {
      var attr = attribution.substring(0,pos);
      box.innerHTML = quote + attr_div + attr + "</div>";
    }
    busy = false;
    }
    if(pos > attrib_len) {
    clearInterval(interval);
    interval = setInterval('show_init()',quote_pause);
    }
    }

1 个答案:

答案 0 :(得分:3)

使用<script>标记加载Javascript文件时,该文件将被执行,而不是作为Javascript对象加载。