升到四个裤衩了 散分 随便问个小问题

wwd252 2008-08-28 09:37:09
先散分,大家有空了,再帮我看看这个小问题



<script type="text/javascript">
// by Go_Rush(阿舜) from http://ashun.cnblogs.com/

var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

function showUrl(element){ //使用哈稀对象
alert(hash[element.value])
}
</script>


昨天 想了解js如何操作hash表的,就到网上搜索了一下。但是上段代码中
function showUrl(element){ //使用哈稀对象
alert(hash[element.value])
}

函数中的element(即哈希对象) 是什么呢?如何声明呢?
Thank in advance
...全文
431 78 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
78 条回复
切换为时间正序
请发表友善的回复…
发表回复
slin60 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yangxinjia 的回复:]
俺是来接分的
[/Quote]
hunter15 2008-08-28
  • 打赏
  • 举报
回复
What is Hash??
tell tell!
wcfboy1 2008-08-28
  • 打赏
  • 举报
回复
我也发个


var Arr =new Array({'s':'sss','aa':'www'},{'s1':'wwww','aa1':'ssss'});
alert(Arr[0].s);
alert(Arr[0].aa);
alert(Arr[1].s1);
alert(Arr[1].aa1);
wdgphc 2008-08-28
  • 打赏
  • 举报
回复
只接
OwenLiu 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 yb1124 的回复:]
HTML code
<html>
<head>
<script type="text/javascript">
// by Go_Rush(阿舜) from http://ashun.cnblogs.com/

var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

function showUrl…
[/Quote]

正解~~~~~!!!
kenryu3450 2008-08-28
  • 打赏
  • 举报
回复
jf
OwenLiu 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 yb1124 的回复:]
HTML code
<html>
<head>
<script type="text/javascript">
// by Go_Rush(阿舜) from http://ashun.cnblogs.com/

var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

function showUrl…
[/Quote]

正解!!!!
oec2003 2008-08-28
  • 打赏
  • 举报
回复
恭喜楼主
jf
mike1lainet 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zl58859173 的回复:]
来帮顶下。。学习。
[/Quote]
liuyun1987 2008-08-28
  • 打赏
  • 举报
回复
GX
cteddy 2008-08-28
  • 打赏
  • 举报
回复
有人回答的很好了啊
我来接分
zhengshaodong 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 wwd252 的回复:]

谢谢大家的踊跃发言,我再帖个hash的例子(刚刚从网上 淘到的 ,吼吼)

JScript code
<script>
var ht1 =
{
userID : "zsw",
userName : "Zhangshiwei"
}
var ht2 =
{
userID : "lht",
userName : "lihaitao"
}
var ht3 =
{
userID : "yhd",
userName : "yanghaidong"
}
var ht = …
[/Quote]

<script>
var ht =
{
"c1" : {"UserID":"userc1","UserName":"usercc1"},
"c2" : {"UserID":"userc2","UserName":"usercc2"},
"c3" : {"UserID":"userc3","UserName":"usercc3"}
};


alert(ht["c1"]["UserID"]);
alert(ht["c2"]["UserID"]);
</script>
wwd252 2008-08-28
  • 打赏
  • 举报
回复

谢谢大家的踊跃发言,我再帖个hash的例子(刚刚从网上 淘到的 ,吼吼)

<script>
var ht1 =
{
userID : "zsw",
userName : "Zhangshiwei"
}
var ht2 =
{
userID : "lht",
userName : "lihaitao"
}
var ht3 =
{
userID : "yhd",
userName : "yanghaidong"
}
var ht =
{
c1 : ht1,
c2 : ht2,
c3 : ht3
};


alert(ht["c1"]["userID"]);
alert(ht["c2"]["userID"]);

</script>


这个也是hash操作吧
浮生若梦丶 2008-08-28
  • 打赏
  • 举报
回复
不好意思,我的js只有幼儿园水平....
freeflying1222 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 cat_hsfz 的回复:]
JScript code
var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

alert(hash["百度"]) //"http://www.baidu.com/"




这样明白了吗?
[/Quote]
我也明白了
zhengshaodong 2008-08-28
  • 打赏
  • 举报
回复
<script>
var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

alert(hash.百度) ; 可以这样
也可以这样
alert(hash["百度"]) ;
</script>
zhengshaodong 2008-08-28
  • 打赏
  • 举报
回复
这个是JSON吧 不过说是哈希也算是吧
但是JSON的格式更自由
比如可以


var j = {"a":{"a1":"1"},"b":{"b1":"3","b2":"4"}};
alert(j.a.a1);
jiang_jiajia10 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 cat_hsfz 的回复:]
JScript code
var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

alert(hash["百度"]) //"http://www.baidu.com/"




这样明白了吗?
[/Quote]
jiang_jiajia10 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 cat_hsfz 的回复:]
JScript code
var hash={
"百度" :"http://www.baidu.com/",
"Google" :"http://www.google.com/",
"微软" :"http://www.microsoft.com/",
"博客园" :"http://www.cnblogs.com/",
"阿舜的博客" :"http://ashun.cmblogs.com/"
};

alert(hash["百度"]) //"http://www.baidu.com/"




这样明白了吗?
[/Quote]
MANION 2008-08-28
  • 打赏
  • 举报
回复
JFJF
加载更多回复(58)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧