如何在javascript的for循环中增加相同标签添加onclick事件
<ulid="tags"><liclass="selectTag"><aonclick="selectTag('tagContent0',this)"href="java...
<ul id="tags">
<li class="selectTag"><a onclick="selectTag('tagContent0',this)" href="javascript:void(0)">The Civil War</a> </li>
<li ><a onclick="selectTag('tagContent1',this)" href="javascript:void(0)">Photo Gallery</a> </li>
<li ><a onclick="selectTag('tagContent2',this)" href="javascript:void(0)">Blog</a> </li>
<li ><a onclick="selectTag('tagContent3',this)" href="javascript:void(0)">Link Library</a> </li>
<li ><a onclick="selectTag('tagContent4',this)" href="javascript:void(0)">Podcast</a> </li>
<li ><a onclick="selectTag('tagContent5',this)" href="javascript:void(0)">Assignment</a></li>
</ul>
<script type="text/javascript">
function selectTag(showContent,selfObj){
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(i=1; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(i=0; j=document.getElementById("tagContent"+i); i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
tagContent5 下面的内弄不显示
那位大哥帮帮忙啊 展开
<li class="selectTag"><a onclick="selectTag('tagContent0',this)" href="javascript:void(0)">The Civil War</a> </li>
<li ><a onclick="selectTag('tagContent1',this)" href="javascript:void(0)">Photo Gallery</a> </li>
<li ><a onclick="selectTag('tagContent2',this)" href="javascript:void(0)">Blog</a> </li>
<li ><a onclick="selectTag('tagContent3',this)" href="javascript:void(0)">Link Library</a> </li>
<li ><a onclick="selectTag('tagContent4',this)" href="javascript:void(0)">Podcast</a> </li>
<li ><a onclick="selectTag('tagContent5',this)" href="javascript:void(0)">Assignment</a></li>
</ul>
<script type="text/javascript">
function selectTag(showContent,selfObj){
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(i=1; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(i=0; j=document.getElementById("tagContent"+i); i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
tagContent5 下面的内弄不显示
那位大哥帮帮忙啊 展开
4个回答
展开全部
function selectTag(showContent,selfObj){
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(var i=0; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(var i=0; j=document.getElementById("tagContent"+i),i<taglength; i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
这个 可以的!
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(var i=0; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(var i=0; j=document.getElementById("tagContent"+i),i<taglength; i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
这个 可以的!
展开全部
function selectTag(showContent,selfObj){
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(var i=0; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(var i=0; j=document.getElementById("tagContent"+i),i<taglength; i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
var tag = document.getElementsByTagName("li");
var taglength = tag.length;
for(var i=0; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
for(var i=0; j=document.getElementById("tagContent"+i),i<taglength; i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
//]]>
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
好像是tag.setAttribute("", "");吧 前面是名字 你这是onclick 后面是值
不过我一般都直接加html的。。
不过我一般都直接加html的。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
利用函数的隐含参数arguments,给函数传参;即:
for(var i=0;i<arguments.length;i++){
var tag = document.getElementsByTagName(arguments[i]);
}
for(var i=0;i<arguments.length;i++){
var tag = document.getElementsByTagName(arguments[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询