首页 | 新闻 | 交流 | 问吧 | 文档 | 手册 | 下载 | 博客

收藏此问题 发表新评论

如何改呀?我实在搞不清楚。

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();

arrItems1[3] = "Truck";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Train";
arrItemsGrp1[4] = 1;
arrItems1[5] = "Car";
arrItemsGrp1[5] = 1;

arrItems1[6] = "Boat";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Submarine";
arrItemsGrp1[7] = 2;

arrItems1[0] = "lanes";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Ultralight";
arrItemsGrp1[1] = 3;
arrItems1[2] = "Glider";
arrItemsGrp1[2] = 3;

var arrItems2 = new Array();
var arrItemsGrp2 = new Array();

arrItems2[21] = "747";
arrItemsGrp2[21] = 0
arrItems2[22] = "Cessna";
arrItemsGrp2[22] = 0

arrItems2[31] = "Kolb Flyer";
arrItemsGrp2[31] = 1
arrItems2[34] = "Kitfox";
arrItemsGrp2[34] = 1

arrItems2[35] = "Schwietzer Glider";
arrItemsGrp2[35] = 2

arrItems2[99] = "Chevy Malibu";
arrItemsGrp2[99] = 05
arrItems2[100] = "Lincoln LS";
arrItemsGrp2[100] = 05
arrItems2[57] = "BMW Z3";
arrItemsGrp2[57] = 05

arrItems2[101] = "F-150";
arrItemsGrp2[101] = 03
arrItems2[102] = "Tahoe";
arrItemsGrp2[102] = 03

arrItems2[103] = "Freight Train";
arrItemsGrp2[103] = 04
arrItems2[104] = "assenger Train";
arrItemsGrp2[104] = 04

arrItems2[105] = "Oil Tanker";
arrItemsGrp2[105] = 6
arrItems2[106] = "Fishing Boat";
arrItemsGrp2[106] = 6

arrItems2[200] = "Los Angelas Class";
arrItemsGrp2[200] = 7
arrItems2[201] = "Kilo Class";
arrItemsGrp2[201] = 7
arrItems2[203] = "Seawolf Class";
arrItemsGrp2[203] = 7

function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
  var myEle ;
  var x ;
  // Empty the second drop down box of any choices
  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  if (control.name == "firstChoice") {
    // Empty the third drop down box of any choices
    for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
  // ADD Default Choice - in case there are no values
  myEle = document.createElement("option") ;
  myEle.value = 0 ;
  myEle.text = "[SELECT]" ;
  controlToPopulate.add(myEle) ;
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ )
    {
      if ( GroupArray[x] == control.value )
        {
          myEle = document.createElement("option") ;
          myEle.value = x ;
          myEle.text = ItemArray[x] ;
          controlToPopulate.add(myEle) ;
        }
    }
}
//  End -->

以上代码,我想改成
arrItems1[03] = "Truck";
arrItemsGrp1[03] = 01;
arrItems1[04] = "Train";
arrItemsGrp1[04] = 01;
arrItems1[05] = "Car";
arrItemsGrp1[05] = 01;
可是就出错了,我应如何是好呀?
是不是应先把01改为字符型,真搞不懂了.
昵称: xi9527  时间: 2005-10-26 15:08:00
如何在javascript数组中用字符串做下标?
昵称: xi9527  时间: 2005-10-26 16:08:00
数组下标必须是0~2e32-1的整数
昵称: liaoshijun2004  时间: 2005-10-26 16:18:00


QUOTE:
最初由 liaoshijun2004 发布
[B]数组下标必须是0~2e32-1的整数 [/B]
就没有解决的方法嘛?
昵称: xi9527  时间: 2005-10-26 16:32:00


QUOTE:
最初由 liaoshijun2004 发布
[B]数组下标必须是0~2e32-1的整数 [/B]
老大你开玩笑吧?

arrItems1['03'] = "Truck";
arrItemsGrp1['03'] = '01';
arrItems1['04'] = "Train";
arrItemsGrp1['04'] = '01';
arrItems1['05'] = "Car";
arrItemsGrp1['05'] = '01';
这样定义是合法的,你说的不行是程序调用此数组出错吧?也许你那段程序把数组索引作为整数运算的
昵称: buzzard  时间: 2005-10-26 18:21:00
PHP会不?数组下标可以是英文中文等的

arr=new Array();
arr['saa']='adc';
arr['o0020']='wprpwpr';
alert(arr);

看Office 某目录下的手册吧
昵称: 纯粹误会  时间: 2005-10-27 01:51:00
我就是不想索引作为整数运算;
而在php中,就可以。
郁闷呀~~~~~~~~~~~~~~~~
昵称: xi9527  时间: 2005-10-27 09:24:00
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array(".NET概论及软件","01","0101");
subcat[1] = new Array("ASP","02","0201");
subcat[2] = new Array("正则","02","0202");
subcat[3] = new Array("邮件","03","0301");
subcat[4] = new Array("开发具","04","0401");
subcat[5] = new Array("MS","05","0501");
subcat[6] = new Array(".NET概论及软件使用","0101","010101");
subcat[7] = new Array("ASP基础","0201","020101");
subcat[8] = new Array("正则表达式","0201","020102");
subcat[9] = new Array("邮件处理","0301","030101");
subcat[10] = new Array("开发工具","0401","040101");
subcat[11] = new Array("MS Access","0501","050101");
onecount=12;
function changelocation(locationid)
{
document.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[1] == locationid)
{
document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[0], subcat[2]);
}
}
function changelocation2(locationid2)
{
document.myform.Nclassid2.length = 0;
var locationid2=locationid2;
var j;
for (j=0;j<cnecount;j++)
{
if(subcat[j][1]==locationid2)
{
document.myform.Nclassid2.options[document.myform.Nclassid2.length] = new Option(subcat[j][0], subcat[j][2]);
}
}
}
}
</script>
<form method="post" name="myform" action="ru_query.php">
<select name="classid" onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>

<option value="01">.Net专区</option>


<option value="02">ASP技术</option>


<option value="03">HP技术</option>


<option value="04">JSP技术</option>


<option value="05">数据库</option>


</select>

<select name="Nclassid" onChange="changelocation2(document.myform.Nclassid.options[document.myform.Nclassid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>
</select>
<select name="Nclassid2">
  <option selected value="">未指定条件</option>
</select>
<input type="submit" name="Submit" value="搜索">
</form>
昵称: xi9527  时间: 2005-10-27 12:21:00
up~~~~~~~~~~~~~~~~~~~~~
昵称: xi9527  时间: 2005-10-27 15:22:00
发表评论
昵称:
内容:
验证: