我第一次点击标题一关闭内容一,然后第二次点击标题二,却发现关闭不了内容二,求各位哥们或者姐们,帮个忙。。谢谢 htmljs 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 window.onload = function(){ var box = document.getElementById('box'), h3s = box.getElementsByTagName('h3'), divs = box.getElementsByTagName('div'); for(var i=0;i<h3s.length;i++){ (function(){ var j = i; h3s[i].onclick = function(){ toggle(divs[j]); } })() } function toggle(e){ e.style.display=="none" ? e.style.display="block" : e.style.display ="none"; }} 发代码,也好过截图呀。<h3>一</h3> <div>111</div> <h3>二</h3> <div>222</div> <h3>三</h3> <div>333</div> <script> var aH3 = document.getElementsByTagName("h3"); for(var i=0; i<aH3.length; i++){ aH3[i].onclick = function(){ this.nextSibling.nextSibling.style.display = (this.nextSibling.nextSibling.style.display && this.nextSibling.nextSibling.style.display=="none")?"block":"none"; } } </script> 要是我加上一个缓冲运动呢?比如:function getStyle(attr,obj){ if(typeof getComputedStyle=="function"){ return window.getComputedStyle(obj,null)[attr]; }else{ return obj.currentStyle[attr]; }}function startMove(obj,json){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var flag=true; for(var attr in json){ if(attr=="opacity"){ var temp=parseInt(parseFloat(getStyle(attr,obj))*100); }else{ var temp=parseInt(getStyle(attr,obj)); } var speed=(json[attr]-temp)/6; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(temp!=json[attr]){ flag=false; } if(attr=="opacity"){ obj.style.opacity=(temp+speed)/100; obj.style.filter='alpha(opacity='+(temp+speed)+')'; }else{ obj.style[attr]=temp+speed+'px'; } } if(flag){ clearInterval(obj.timer); } },30);}window.onload = function(){ var box = document.getElementById('box'), h3s = box.getElementsByTagName('h3'), divs = box.getElementsByTagName('div'); for(var i=0;i<h3s.length;i++){ (function(){ var j = i; h3s[i].onclick = function(){ toggle(divs[j]); } })() } function toggle(e){ // e.style.display=="none" ? e.style.display="block" : e.style.display ="none"; var h=parseInt(getStyle("height",e)); h=h==0?50:0; startMove(e,{ height:h }) }}上面的我就是根据你的代码改写的有没有更加优化的代码??? 要是我加上一个缓冲运动呢?比如:function getStyle(attr,obj){ if(typeof getComputedStyle=="function"){ return window.getComputedStyle(obj,null)[attr]; }else{ return obj.currentStyle[attr]; }}function startMove(obj,json){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var flag=true; for(var attr in json){ if(attr=="opacity"){ var temp=parseInt(parseFloat(getStyle(attr,obj))*100); }else{ var temp=parseInt(getStyle(attr,obj)); } var speed=(json[attr]-temp)/6; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(temp!=json[attr]){ flag=false; } if(attr=="opacity"){ obj.style.opacity=(temp+speed)/100; obj.style.filter='alpha(opacity='+(temp+speed)+')'; }else{ obj.style[attr]=temp+speed+'px'; } } if(flag){ clearInterval(obj.timer); } },30);}window.onload = function(){ var box = document.getElementById('box'), h3s = box.getElementsByTagName('h3'), divs = box.getElementsByTagName('div'); for(var i=0;i<h3s.length;i++){ (function(){ var j = i; h3s[i].onclick = function(){ toggle(divs[j]); } })() } function toggle(e){ // e.style.display=="none" ? e.style.display="block" : e.style.display ="none"; var h=parseInt(getStyle("height",e)); h=h==0?50:0; startMove(e,{ height:h }) }}上面的我就是根据你的代码改写的有没有更加优化的代码???直接用jq的特效 如何获取iframe跨域的高度 求教 JS 查找 IFRAME页面中的内容? 怎么样取得一组checkbox的个数? 如下功能的导航栏怎么写?或者给点思路! 请教: 如何将一个多位小数的值保留2位小数? 请问怎样控制图片可以成比例缩小? 谁知道Windows Update网站中添加到下载的功能特效的原理? 马上给分,我的frm怎么不提交呢? 有人作过关于打印的组件嘛??请教思路 一个十分常见的问题,解决不是很好,总觉得别扭 easyui datagrid分页无效 求大神帮忙,小弟急等!!!!
var box = document.getElementById('box'),
h3s = box.getElementsByTagName('h3'),
divs = box.getElementsByTagName('div');
for(var i=0;i<h3s.length;i++){
(function(){
var j = i;
h3s[i].onclick = function(){
toggle(divs[j]);
}
})()
}
function toggle(e){
e.style.display=="none" ? e.style.display="block" : e.style.display ="none";
}
}
<h3>一</h3>
<div>111</div>
<h3>二</h3>
<div>222</div>
<h3>三</h3>
<div>333</div>
<script>
var aH3 = document.getElementsByTagName("h3");
for(var i=0; i<aH3.length; i++){
aH3[i].onclick = function(){
this.nextSibling.nextSibling.style.display = (this.nextSibling.nextSibling.style.display && this.nextSibling.nextSibling.style.display=="none")?"block":"none";
}
}
</script>
比如:function getStyle(attr,obj){
if(typeof getComputedStyle=="function"){
return window.getComputedStyle(obj,null)[attr];
}else{
return obj.currentStyle[attr];
}
}
function startMove(obj,json){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var flag=true;
for(var attr in json){
if(attr=="opacity"){
var temp=parseInt(parseFloat(getStyle(attr,obj))*100);
}else{
var temp=parseInt(getStyle(attr,obj));
}
var speed=(json[attr]-temp)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(temp!=json[attr]){
flag=false;
}
if(attr=="opacity"){
obj.style.opacity=(temp+speed)/100;
obj.style.filter='alpha(opacity='+(temp+speed)+')';
}else{
obj.style[attr]=temp+speed+'px';
}
}
if(flag){
clearInterval(obj.timer);
}
},30);
}
window.onload = function(){
var box = document.getElementById('box'),
h3s = box.getElementsByTagName('h3'),
divs = box.getElementsByTagName('div');
for(var i=0;i<h3s.length;i++){
(function(){
var j = i;
h3s[i].onclick = function(){
toggle(divs[j]);
}
})()
}
function toggle(e){
// e.style.display=="none" ? e.style.display="block" : e.style.display ="none";
var h=parseInt(getStyle("height",e));
h=h==0?50:0;
startMove(e,{
height:h
})
}
}上面的我就是根据你的代码改写的有没有更加优化的代码???
比如:function getStyle(attr,obj){
if(typeof getComputedStyle=="function"){
return window.getComputedStyle(obj,null)[attr];
}else{
return obj.currentStyle[attr];
}
}
function startMove(obj,json){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var flag=true;
for(var attr in json){
if(attr=="opacity"){
var temp=parseInt(parseFloat(getStyle(attr,obj))*100);
}else{
var temp=parseInt(getStyle(attr,obj));
}
var speed=(json[attr]-temp)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(temp!=json[attr]){
flag=false;
}
if(attr=="opacity"){
obj.style.opacity=(temp+speed)/100;
obj.style.filter='alpha(opacity='+(temp+speed)+')';
}else{
obj.style[attr]=temp+speed+'px';
}
}
if(flag){
clearInterval(obj.timer);
}
},30);
}
window.onload = function(){
var box = document.getElementById('box'),
h3s = box.getElementsByTagName('h3'),
divs = box.getElementsByTagName('div');
for(var i=0;i<h3s.length;i++){
(function(){
var j = i;
h3s[i].onclick = function(){
toggle(divs[j]);
}
})()
}
function toggle(e){
// e.style.display=="none" ? e.style.display="block" : e.style.display ="none";
var h=parseInt(getStyle("height",e));
h=h==0?50:0;
startMove(e,{
height:h
})
}
}上面的我就是根据你的代码改写的有没有更加优化的代码???
直接用jq的特效