作者:笑如夏风_503 | 来源:互联网 | 2023-05-18 16:14
var arr1 = new Array();
arr1[0] = new Array (1,1,"├标准");
arr1[1] = new Array (1,15,"│ ├法规");
arr1[2] = new Array (1,19,"│ ├文件");
arr1[3] = new Array (1,2,"├队伍");
arr1[4] = new Array (1,3,"├动态");
arr1[5] = new Array (1,47,"│ ├领导");
arr1[6] = new Array (2,48,"│ ├工作");
arr1[7] = new Array (2,49,"│ ├推普");
var cTmp = "";
var j = 1;
var arr2 = [1,15,19];
var arr3= [];
for(var s in arr1){
for(var x in arr2){
if(arr1[s][1]==arr2[x]){
arr3.push(arr1[s][0],arr1[s][1],arr1[s][2]);
}
}
}
alert(arr3);
alert的arr3没有任何输出,不知是哪里出了问题。
16 个解决方案
这个是全部的代码,没有任何反映,楼上的是怎么测试的呢?
哦,输出是正常的,我的浏览器把Javascript禁用了。
另外就是我的输出怎么是一维数组呢,我想输出二维数组需要怎么来写代码呢?
var arr1 = new Array();
arr1[0] = new Array (1,1,"├标准");
arr1[1] = new Array (1,15,"│ ├法规");
arr1[2] = new Array (1,19,"│ ├文件");
arr1[3] = new Array (1,2,"├队伍");
arr1[4] = new Array (1,3,"├动态");
arr1[5] = new Array (1,47,"│ ├领导");
arr1[6] = new Array (2,48,"│ ├工作");
arr1[7] = new Array (2,49,"│ ├推普");
function InitSelect(Obj,ChannelId,ChkID,
AdminName)
{
var AdminName = new Array();//如果直接定义AdminName = [1,15,19]就正常输出,如果调用上面红色的AdminName 就没有输出,这段代码是下拉菜单的代码,jordan102还在吗?
var arr3 = new Array();
for(var s in arr1){
for(var x in AdminName){
if(arr1[s][1]==AdminName[x]){
arr3.push(arr1[s]);
}
}
}
var cTmp = "";
var j = 1;
Obj.length = 0;
Obj.options[Obj.length] = new Option("点这里选择分类", "");
for(var i=0;i
{
if(arr3[i][0]==ChannelId)
{
Obj.options[Obj.length] = new Option(arr3[i][2], arr3[i][1]);
if(arr3[i][1]==ChkID)
Obj.selectedIndex = j;
j = j + 1;
if(i+1 {
if(arr3[i+1][0]!=ChannelId)
break;
}
}
}
}
只有上面红色的部分是有问题的,其余的部分都是正确的,我都贴出来是为了判断程序更方便一些
传进来的 AdminName 是什么类型?
var AdminName = new Array(); 这句有什么用,AdminName 就是那个数组啊
AdminName 是从数据库读取并传递过来的,
,1,2,3,4,5,6,
是上面这种类型的,我需要怎么操作才能把传递过来的AdminName 定义为一维数组呢?
var AdminName = new Array();
==>
var AdminName = AdminName.split(',');
还是不行,我在asp里面把,1,2,3,4,5,6,前后的逗号去掉了然后使用var AdminName = AdminName.split(',');还是没有输出。
你传入的 AdminName 是什么类型。这样吧:
alert(AdminName); alert(typeof AdminName);
var AdminName = AdminName.split(',');
alert(AdminName); alert(typeof AdminName);
分别是什么结果。
var arr1 = new Array();
arr1[0] = new Array (1,1,"├标准");
arr1[1] = new Array (1,15,"│ ├法规");
arr1[2] = new Array (1,19,"│ ├文件");
arr1[3] = new Array (1,2,"├队伍");
arr1[4] = new Array (1,3,"├动态");
arr1[5] = new Array (1,47,"│ ├领导");
arr1[6] = new Array (2,48,"│ ├工作");
arr1[7] = new Array (2,49,"│ ├推普");
function InitSelect(Obj,ChannelId,ChkID,AdminName)
{
alert(AdminName); alert(typeof AdminName);
var AdminName = AdminName.split(',');
alert(AdminName); alert(typeof AdminName);
//我分别在这把这两个alert放到上面都没有提示框出现,是不是asp传递给js的字符串有限制呢?
var AdminName = new Array();
var arr3 = new Array();
for(var s in arr1){
for(var x in AdminName){
if(arr1[s][1]==AdminName[x]){
arr3.push(arr1[s]);
}
}
}
var cTmp = "";
var j = 1;
Obj.length = 0;
Obj.options[Obj.length] = new Option("点这里选择分类", "");
for(var i=0;i
{
if(arr3[i][0]==ChannelId)
{
Obj.options[Obj.length] = new Option(arr3[i][2], arr3[i][1]);
if(arr3[i][1]==ChkID)
Obj.selectedIndex = j;
j = j + 1;
if(i+1{
if(arr3[i+1][0]!=ChannelId)
break;
}
}
}
}
我在调用上面函数function InitSelect(Obj,ChannelId,ChkID,AdminName)
的asp页面输出AdminName是正常的1,15,19
可能就是你调用有问题。用firebug看看控制台报什么错。