Javascript 更改变量名后JS脚本无法正常工作

Javascript 更改变量名后JS脚本无法正常工作,javascript,Javascript,我正在为一个客户的网站工作。我已经编写了一些javascript,可以为客户打印链接列表,但它的工作方式与预期不同。你可以找到这个文件。它应该打印三列,但只打印前两列。在我更改一些变量名之前,这是可以使用的。可能出了什么问题?请参阅grizfirestarters.com/stores_dyn.htm上的完成页面 编辑:我已经通过设置列大小而不是动态来解决这个问题。有点失去了乐趣,但完成了任务。代码如下: /**************** Author: Timothy Grindall Co

我正在为一个客户的网站工作。我已经编写了一些javascript,可以为客户打印链接列表,但它的工作方式与预期不同。你可以找到这个文件。它应该打印三列,但只打印前两列。在我更改一些变量名之前,这是可以使用的。可能出了什么问题?请参阅grizfirestarters.com/stores_dyn.htm上的完成页面

编辑:我已经通过设置列大小而不是动态来解决这个问题。有点失去了乐趣,但完成了任务。代码如下:

/****************
Author: Timothy Grindall
Copyright: Timothy Grindall 2008

Note: the array "city_name_wash" is passed to this script by another script that is loaded on the same page and does not need to be included in this script.
Liscense: GNU Public Liscense. Note: if you don't know what the GNU public liscense is, you can probably find out by searching in Wikipedia at "http://www.wikipedia.org". A GNU Public Liscense basically means that you can use this code in any way you like as long as you don't sell the whole or any part of it in the original javascript or in a translated and/or compiled form.
*********************/

/**************************
*    format and print     *
**************************/

// *** Start Washington stores *** //

wash_col_size = Math.floor(city_name_wash.length / 3);

add_count = 2;

// calculate difference between rounded wash_col_size and unrounded wash_col_size. If there is a difference we need to compensate for extra cities/entries by making slightly longer columns

if ( (city_name_wash.length - (wash_col_size*3)) != 0 ) {
    wash_col_size = wash_col_size + add_count;
}

document.write("<div id='cities_wrapperL'>");//begin cities_wrapperL

for (i=0; i < wash_col_size*2; i++) {

    // prepare a link name from the city name
    link_name = city_name_wash[i].split(" (")[0]; // finds the first part of the name minus the "()"s on the end

    document.write("<div id='cityL'><a href='fixjava.htm' onclick='javascript: window.location = \"store_info_map.html?img=\" + this image + \"&city = " + link_name + "\"; return false;'> + city_name_wash[i] + "</ a></div>");

    i++; // increment counter

    // prepare a link name from the city name
    link_name = city_name_wash[i].split(" (")[0]; // finds the first part of the name minus the "()"s on the end

    document.write("<div id='cityC'><a href='fixjava.htm' onclick='javascript: window.location = \"store_info_map.html?img=\" + this_image + \"&city=" + link_name + "\"; return false;'>" + city_name_wash[i] + "</ a></div>");

}

document.write("</div><div id='cities_wrapperR'>"); // end of cities_wrapperL and start of cities_wrapperR


for ( i = wash_col_size*2; i < wash_col_size*3; i++){

    // prepare a link name from the city name
    link_name = city_name_wash[i].split(" (")[0]; // finds the first part of the name minus the "()"s on the end

    document.write("<div id='cityR'><a href='fixjava.htm' onclick = 'javascript: window.location = \"store_info_map.html?img = \" + this_image + \"&city = " + link_name + "\"; return false;'> + city_name_wash[i] + "</ a></div>");

}

document.write("</div>"); // end of cities_wrapperR

// *** start Idaho stores *** //


var content = document.getElementsByName("content")[0];
content.id = "short-back" + (wash_col_size - 3); // set to id that has the same positioning, but a different background image
if ( wash_col_size < 4 ) content.id = "short-back"; // in case there is three or less
if ( wash_col_size > 9 ) content.id = "main-content_stores"


/**************************
*     target example:     *
**************************/

/*
<div id="cities_wrapperL">
    <div id="cityL"><a href="Aberdeen.htm">Aberdeen</a></div>
    <div id="cityC"><a href="Gold Bar.htm">Gold Bar</a></div>
    <div id="cityL"><a href="Anacortes.htm">Anacortes</a></div>
    <div id="cityC"><a href="Granite_Falls.htm">Granite Falls</a></div>
    <div id="cityL"><a href="Arlington.htm">Arlington (2)</a></div>
    <div id="cityC"><a href="Hoodsport.htm">Hoodsport</a></div>
    <div id="cityL"><a href="Bellingham.htm">Bellingham (2)</a></div>
    <div id="cityC"><a href="Joyce.htm">Joyce (2)</a></div>
</div>
<div id="cities_wrapperR">
    <div id="cityR"><a href="Port_Angeles.htm">Port Angeles</a></div>
    <div id="cityR"><a href="Port_Townsend.htm">Port Townsend (2)</a></div>
    <div id="cityR"><a href="Poulsbo.htm">Poulsbo (2)</a></div>
    <div id="cityR"><a href="Randle.htm">Randle</a></div>
</div>
*/
/****************
作者:蒂莫西·格林德尔
版权所有:Timothy Grindall 2008
注意:数组“city_name_wash”由加载在同一页面上的另一个脚本传递到此脚本,不需要包含在此脚本中。
Liscense:GNU公共Liscense。注意:如果你不知道GNU公共许可证是什么,你可以通过在维基百科中搜索找到“http://www.wikipedia.org". GNU Public Liscene基本上意味着您可以以任何方式使用此代码,只要您不以原始javascript或翻译和/或编译的形式出售其全部或任何部分。
*********************/
/**************************
*格式和打印*
**************************/
//***开设华盛顿门店***//
wash\u col\u size=数学楼层(城市名称\u wash.length/3);
加上计数=2;
//计算四舍五入洗涤颜色大小和未四舍五入洗涤颜色大小之间的差异。如果存在差异,我们需要通过稍微加长列来补偿额外的城市/条目
如果((城市名称洗涤长度-(洗涤颜色大小*3))!=0){
清洗颜色大小=清洗颜色大小+添加计数;
}
文件。填写(“”)//开始城市包装
对于(i=0;i
在我更改一些变量名之前,这是正常工作的。可能出了什么问题

只是猜测一下,你把更改变量名塞得满满当当——把它们改回去,然后重新开始,或者不要再碰它们,这取决于你的感受——看看代码,它看起来比2008年的版权日期要早,我建议把代码拖到现代


或者,在您喜欢的任何浏览器中查看开发者控制台,发现第45行有一个未定义的变量,即
city\u count

,您能否将您的代码包含在问题本身中,而不仅仅是链接到它?我们不会从如此外部的代码中挖掘您的错误。请添加与您的问题相关的代码到邮局去,然后我们会看到。。。