社区
JavaScript
帖子详情
高分求救, 低难度(我是菜鸟), 高分数(你是高手)
shingle
2002-10-31 01:00:56
<script language="javaScript" >
aArray = new Array(
new Array(
"aa",
"ab",
"ac",
new Array(
"ada",
"adb"
),
"ae"
),
"b",
"c",
"d"
);
function showA( A )
{
//如何在这里显示 aArray 的每一个无素( 遍历到每一个元素)
}
</script>
...全文
28
10
打赏
收藏
高分求救, 低难度(我是菜鸟), 高分数(你是高手)
aArray = new Array( new Array( "aa", "ab", "ac", new Array( "ada", "adb" ), "ae" ), "b", "c", "d" ); function showA( A ) { //如何在这里显示 aArray 的每一个无素( 遍历到每一个元素) }
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
shingle
2002-11-03
打赏
举报
回复
不好意思
本来当天解决问题当天给分, 只可惜 CSDN 服务器太忙, 老提交不上,
很报歉, 分我照样给, 不成谢意!!!
这是 JAVA 生成的树, 在 javaScript 中还真的好用
<script language="javaScript">
//树节点的数据结构
function node( name, value, child )
{
this.name = name;
this.value = value;
this.child = child;
}
//将一个下拉列表的所有项目删除
function removeAllItem( aSelect )
{
if( aSelect.options != null )
{
var count = aSelect.options.length
for( var i = 0; i < count ; i++ )
{
aSelect.remove( 0 );
}
}
}
//在树内部递归搜索
function searchInTree( tree, val )
{
if( tree != null && tree.child != null )
{
if( tree.value == val )return tree;
for( var i = 0; i < tree.child.length; i++ )
{
if( tree.child != null )
{
var aNode = searchInTree( tree.child[i], val );
if( aNode != null )return aNode;
}
}
}
return null;
}
//将一个节点的所了项目加到下拉列表的项目中去
function goOverANode( aNode, aSelect )
{
if( aNode != null && aNode.child != null )
{
for( var i = 0; i < aNode.child.length; i++ )
{
aSelect.add( new Option( aNode.child[i].name, aNode.child[i].value ) );
}
}
}
//查找节点, 更新下拉列表
function searchAndMade( tree, aSelect, val )
{
removeAllItem( aSelect );
aSelect.add( new Option( "请选择", "" ) );
var nd = searchInTree( tree, val );
goOverANode( nd, aSelect );
}
//生成数据树
aTree = new node ( "属于板块名称", "0",
new Array(
new node ( "团购首页", "6",
new Array(
new node ( "团购博士", "9", null ) ,
new node ( "楼盘追踪", "17", null ) ,
new node ( "购房常识", "22", null ) ,
new node ( "人物专访", "28", null ) ,
new node ( "金融咨询", "35", null ) ,
new node ( "公告板", "43", null ) ,
new node ( "行业动态", "912", null )
)
) ,
new node ( "房屋团购", "52",
new Array(
new node ( "行业动态", "62", null ) ,
new node ( "政策法规", "72", null ) ,
new node ( "购房常识", "82", null )
)
) ,
new node ( "汽车团购", "92",
new Array(
new node ( "行业动态", "102", null ) ,
new node ( "政策法规", "112", null ) ,
new node ( "新车看台", "132", null ) ,
new node ( "购车常识", "142", null )
)
) ,
new node ( "建材团购", "152",
new Array(
new node ( "行业动态", "162", null ) ,
new node ( "政策法规", "172", null ) ,
new node ( "质量看台", "182", null ) ,
new node ( "诚信档案", "192", null )
)
) ,
new node ( "家装团购", "212",
new Array(
new node ( "温馨家园", "732", null ) ,
new node ( "诚信档案", "842", null ) ,
new node ( "行业动态", "672", null ) ,
new node ( "流行趋势", "852", null ) ,
new node ( "家装常识", "882", null )
)
)
)
) ;
</script>
huangyq
2002-10-31
打赏
举报
回复
学ing
孟子E章
2002-10-31
打赏
举报
回复
http://lucky.myrice.com/javascriptexam/add_del_Select.htm
bencalie
2002-10-31
打赏
举报
回复
<script>
// 添加选项
function addOption(pos){
var objSelect = document.myForm.mySelect;
// 取得字段值
var strName = document.myForm.myOptionName.value;
var strValue = document.myForm.myOptionValue.value;
// 建立Option对象
var objOption = new Option(strName,strValue);
if (pos == -1 & pos > objSelect.options.length)
objSelect.options[objSelect.options.length] = objOption;
else
objSelect.add(objOption, pos);
}
// 删除选项
function deleteOption(type){
var objSelect = document.myForm.mySelect;
if(objSelect.options.length>0){
if (type == true)
objSelect.options[objSelect.selectedIndex] = null;
else
objSelect.remove(objSelect.selectedIndex);
}
else
alert("已经没有选项可以删除了!")
}
// 显示选项信息
function showOption(objForm){
var objSelect = objForm.mySelect;
if(objSelect.options.length>0){
document.all.myOptionName.value = objSelect.options[objSelect.selectedIndex].text;
document.all.myOptionValue.value = objSelect.options[objSelect.selectedIndex].value;
}
else
alert("没有选项可以显示!")
}
</script>
<form name="myForm">
<select name="mySelect">
<option value="value1" Selected>HTML</option>
<option value="value2">JavaScript</option>
<option value="value3">VBScript</option>
</select>
<input type="button" onclick="showOption(this.form)" value="显示">
<input type="button" onclick="deleteOption(true)" value="删除">
<input type="button" onclick="deleteOption(false)" value="Remove方法"><br><br>
选项名称 : <input type="text" name="myOptionName" value="CSS"><br>
选项的值 : <input type="text" name="myOptionValue" value="value4">
<input type="button" onclick="addOption(-1)" value="添加">
<input type="button" onclick="addOption(0)" value="插入">
</form>
shingle
2002-10-31
打赏
举报
回复
多谢 !
net_lover(孟子E章)
代码我己完成如下, 还请指点一二
<script language="javaScript" >
aArray = new Array(
new Array(
"aa",
"ab",
"ac",
new Array(
"ada",
"adb"
),
"ae"
),
"b",
"c",
"d"
);
function showA( A )
{
for( var i = 0; i < A.length; i ++ )
{
if( typeof( A[i] ) == "object" )
{
showA( A[i] );
}else{
alert( A[i] );
}
}
}
</script>
不过还有一事不能解决, 我怎样才能在一个 Select 中动态地增删选项呢?
我想清空一个 select 选项然后重新加入新的选项, 请问如何能实现? 谢谢
bencalie
2002-10-31
打赏
举报
回复
上面我贴错了,抱歉
<script language="javaScript" >
aArray = new Array(new Array("aa","ab","ac",new Array("ada","adb"),"ae"),"b","c","d");
function showA( A )
{
var aa=aArray.toString().split(",")
for(i=0;i<aa.length;i++)
alert(aa[i]) //如何在这里显示 aArray 的每一个无素( 遍历到每一个元素)
}
showA()
</script>
bencalie
2002-10-31
打赏
举报
回复
<table id=a1>
<tr><td id=a1b1>一个表格的单元格</td></tr>
<tr><td id=a1b2>一个表格的单元格</td></tr>
<tr><td id=a1b3>一个表格的单元格</td></tr>
</table>
<script>
for(i=1;i<=document.all.a1.all.tags("TD").length;i++)
eval("document.all.a1b"+i).runtimeStyle.background='black'
</script>
=======================
区分 Array 与 String:
使用typeof(对象)方法
<script>
var a=new Array()
var b=new String()
alert(typeof(a))
alert(typeof(b))
</script>
shingle
2002-10-31
打赏
举报
回复
我想用这个东西生成一颗树, 但只知道数组中可以有不同种类的数据( 我只用 Array 与 String ), 不知道怎么区分 Array 与 String
孟子E章
2002-10-31
打赏
举报
回复
<script language="javaScript" >
aArray = new Array(new Array("aa","ab","ac",new Array("ada","adb"),"ae"),"b","c","d");
showA()
function showA()
{
for(i=0;i<aArray.length;i++)
{
if(typeof(aArray[i])=="object")
{
for(j=0;j<aArray[i].length;j++)
{
if(typeof(aArray[i][j])=="object")
{
for(m=0;m<aArray[i][j].length;m++)
alert(aArray[i][j][m])
}
else
alert(aArray[i][j])
}
}
else
alert(aArray[i])
}
}
</script>
bencalie
2002-10-31
打赏
举报
回复
<script language="javaScript" >
aArray = new Array(new Array("aa","ab","ac",new Array("ada","adb"),"ae"),"b","c","d");
function showA()
{
alert(aArray) //如何在这里显示 aArray 的每一个无素( 遍历到每一个元素)
}
showA()
</script>
leetcode在哪-leetcode-lld-flipkart-coding-blox::laptop:机器编码-leetcodeLLD(codingbl
leetcode在哪leetcode-lld-flipkart-coding-blox 机器编码 - leetcode LLD (coding blox) 我的方法: 编码块 Coding Blox 是一个在线编码平台,允许用户注册、创建竞赛和参加由其他人主办的竞赛。 每场比赛都可以有一个级别(
低
、中、
高
),并将包含一组问题。 每个问题都有不同的
难度
级别(
低
、中、
高
)和
分数
。 根据比赛级别,将决定问题集。
低
难度
的比赛级别将有
低
难度
级别的问题。 最终
分数
将根据为比赛选择的
难度
级别决定 用户解决问题并根据问题的
难度
和用户的比赛
分数
更新后获得积分。 您必须设计具有以下功能的 Coding Blox 平台。 命令: CreateUser
:提供用户名注册一个默认
分数
为 1500 的用户。例如: CreateUser Ross CreateUser Monica CreateUser Joey CreateUser Chandler 命令: CreateQuestion
例如:CreateQuestion “LOW” 10 AutoI
小 J 的命运
每次考试成绩出来,只要比上一次考的
分数
高
,小 J 就会受到妈妈的表扬,奖励一瓶“涨芝士”酸奶;其实,小 J 的水平基本上变化不大,但是每次试卷的
难度
却参差不齐,分
高
分
低
完全取决于试卷的
难度
系数。
难度
系数较
高
的试卷,小 J 考的
分数
一定较
低
,相同
难度
系数时,
分数
也相同。现在,班主任李老师已经将本学期要测试的试卷准备好了,请你通过试卷
难度
系数,分析一下小 J 在本学期即将挨揍的次数,以及受到表扬的次数。一行,包含 2 个整数,分别表示小 J 挨揍的次数,与受表扬的次数,中间用一个空格隔开。
致想制作游戏的朋友们
话说在前面,如果你认为你是
高
手
,那么我在这篇文章中说的任何话对你是毫无意义的,你可以无视它。如果你是
菜鸟
,那么我告诉你,我不是
高
手
,我是
菜鸟
,跟你们这些看到题目而进来的
菜鸟
一样菜,或者是比你们还要菜。我在这里也说的话也不带有任何说教的口气,我希望我在这里所说的一切,都能给你们以动力。 自信 我要说的这一点,可能是一个策划最伟大,也是做为一个人最伟大的素质。那就是“我能做得更好!”难...
python基础练习题:转换
分数
【
难度
:1级】--景越Python编程实例训练营,不同
难度
Python习题,适合自学Python的新手进阶
python基础练习题:转换
分数
【
难度
:1级】: 你是在一个
低
级别联赛的足球场工作,你一直在负责自动化记分牌. 裁判会喊出来的
分数
,你已经设置了语音识别模块果然,裁判的语音转换成字符串,但口语成绩需要转换成记分牌的阵! 例如 "的
分数
是四比零" 应该返回 [4,0] 注意:得分不会去上述9个球任一侧( [9,9] ), &...
三菱plc字
高
八位和
低
八位_什么是
低
字节
高
字位,
高
字节
低
字位
我是
菜鸟
,希望能详细些最佳答案一个WORD分为2个BYTE.每个BYTE里有BIT0到BIT78个BOOL位。拿S7300/400PLC来讲。假设MW0是一个字。那么MB0就是
高
字节,MB1是
低
字节MW0MB0MB1B7B6B5B4B3B2B1B0B7...
JavaScript
87,776
社区成员
224,623
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章