function ff_CselRegion_action(element, action)
{
country = ff_getElementByName('CselCountry');
state = ff_getElementByName('CselState');
var America_NorthArray = new Array('Antigua and Barbuda', 'Canada', 'Greenland', 'USA', 'Mexico');
if (element.value == 'none') {
// drop countries
while (country.options.length > 0)
country.options[country.options.length-1] = null;
} else {
// get the matching array
var selectedArray = eval(element.value+'Array');
// drop supernumerous option
while (selectedArray.length < country.options.length-1)
country.options[country.options.length-1] = null;
// add the new options
country.options[0] = new Option('Select Country', 'none', true, true);
for (var i = 0; i < selectedArray.length; i++)
country.options[i+1] =
new Option(selectedArray[i], selectedArray[i]);
} // if
// drop states
while (state.options.length > 0)
state.options[state.options.length-1] = null;
} // ff_CselRegion_action
function ff_CselCountry_action(element, action)
{
state = ff_getElementByName('CselState');
var stateArrayAntigua and Barbuda = new Array(
'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul'
var selectedArray = eval('stateArray'+element.value);
if (selectedArray == null) {
while (state.options.length > 0)
state.options[(state.options.length - 1)] = null;
} else {
// drop supernumerous option
while (selectedArray.length < state.options.length-1)
state.options[state.options.length-1] = null;
// add the new options
state.options[0] = new Option('Select State', 'none', true, true);
for (var i=0; i < selectedArray.length; i++)
state.options[i+1] = new Option(selectedArray[i], selectedArray[i]);
} // if
} //ff_CselCountry_action
我正在尝试找到(var stateArrayAntigua and Barbuda
)的解决方案,因为它有空格而不能&#34;看到&#34;安提瓜和巴布达&#39;在(var America_NorthArray
)。由于我是编程新手,我希望您的答案尽可能简单。提前谢谢
P.S。我在互联网上搜索但我还没有设法解决这个问题。
答案 0 :(得分:0)
变量名称中不能包含空格。设为var stateArrayAntigua_and_Barbuda
并且您很高兴(如果您的代码没有其他问题)。
如果您想更深入地了解这一点,可能需要阅读this,但基本上您最好在变量中使用拉丁字母数字_
和$
'名字。
行中的PS
var stateArrayAntigua and Barbuda = new Array(
'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul'
您还遇到语法错误:缺少结束括号。