Javascript 小问题..

sunlovesea 2009-01-14 03:00:06
function Hide(obj)
{
var objContent=document .getElementById(obj);
if(objContent.style .display =="")
{
objContent .style.display="none";
}
else
{
objContent .style.display=""
}
}

上面一段代码是控制对象的显示/隐藏的代码,调用方法"Hide('divTt')"
如果我想这样调用"Hide(divTt)" 感觉这样比较方便,上面的Js代码该怎么改呢?
我尝试拼接字符串不行...
...全文
117 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ning823 2009-01-14
  • 打赏
  • 举报
回复
mark
Jack123 2009-01-14
  • 打赏
  • 举报
回复
var divMusicLsts = document.getElementById('divTt');
if(divMusicLsts.style.display == "none")
{
divMusicLsts.style.display="block"
}
else
{
divMusicLsts.style.display="none"
}
mengxj85 2009-01-14
  • 打赏
  • 举报
回复
Up
Hide(this)
---
或者用四楼的方法
lixiaozhong 2009-01-14
  • 打赏
  • 举报
回复
刚才看错了

你这样改就可以了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script>
function Hide(obj)
{
var objContent=obj;

if(objContent.style.display =="")
{
objContent.style.display="none";
b1.value="显示文字";
}
else
{
objContent.style.display="";
b1.value="隐藏文字";
}
}

</script>
</head>
<body>
<div id="divTt">是不是要这样调用呀</div>
<input id="b1" type=button value="隐藏文字" onclick=" Hide(divTt)" />
</body>
</html>
sunlovesea 2009-01-14
  • 打赏
  • 举报
回复
【紫陌佳佳】你的方法不行啊..
JGood 2009-01-14
  • 打赏
  • 举报
回复
你可以这样:eval("Hide('divTt')");
vlysses 2009-01-14
  • 打赏
  • 举报
回复
function Hide(obj)
{
if(obj.style .display =="")
{
obj.style.display="none";
}
else
{
obj.style.display=""
}
}

传过来的参数obj必须是var obj=document .getElementById("obj")获得的

lixiaozhong 2009-01-14
  • 打赏
  • 举报
回复
是不是这样调用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script>
function Hide(obj)
{
var objContent=document.getElementById(obj);

if(objContent.style.display =="")
{
objContent.style.display="none";
b1.value="显示文字";
}
else
{
objContent.style.display="";
b1.value="隐藏文字";
}
}
function transfer(obj)
{
eval("Hide('"+obj+"')");

}
</script>
</head>
<body>
<div id="t1">是不是要这样调用呀</div>
<input id="b1" type=button value="隐藏文字" onclick="transfer('t1')" />
</body>
</html>

jiang_jiajia10 2009-01-14
  • 打赏
  • 举报
回复

function allmbarShowHideDiv()
{
var divMusicLsts = document.getElementById("divnone");
if(divMusicLsts.style.display == "none")
{
divMusicLsts.style.display="block"
}
else
{
divMusicLsts.style.display="none"
}
}
lyvscf 2009-01-14
  • 打赏
  • 举报
回复
在你的事件里面直接 "javascript:"Hide('divTt')"

62,268

社区成员

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

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

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

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