首页 新闻 会员 周边

js封装了一个选项卡,调用两次使用会出错

0
悬赏园豆:30 [已解决问题] 解决于 2018-09-20 11:54

// function change(cha){
// btns = $(cha.btnsId).children;
// conts = $(cha.contsId).children;
//// console.log(conts);
// for (var i=0;i<btns.length-1;i++) {
// btns[i].index = i;
// console.log(btns[i]);
//// console.log(conts);
// btns[i].onclick=function(){
// console.log(this)
// for (var j=0;j<conts.length;j++) {
// btns[j].className = cha.btnsClassNormal;
// conts[j].style.display = "none";
// console.log(conts);
// }
// this.className = cha.btnsClassSpecial;
// conts[this.index].style.display = "block";
// }
// }
//
// }
// change({
// btnsId:"click",
// contsId:"table",
// btnsClassNormal:"a",
// btnsClassSpecial:"b"
// });
// change({
// btnsId:"button",
// contsId:"text",
// btnsClassNormal:"title_noraml",
// btnsClassSpecial:"title_specil"
// });

少_年的主页 少_年 | 初学一级 | 园豆:119
提问于:2018-09-19 14:45
< >
分享
最佳答案
0

起码你要 把 报错信息贴出来吧。。。 (翻译成英文 括号内删除)

收获园豆:20
blurs | 小虾三级 |园豆:660 | 2018-09-20 10:08

不报错,错误单个使用没有问题,调用两次以后使用就会出问题,而且调用两次之后,我想操控的是两个选项卡。理论上来说是可以的,结果调用两次之后实现的就是,操作的是同一个选项卡。不报错,所以不知道贴什么错。

少_年 | 园豆:119 (初学一级) | 2018-09-20 10:46

@Faith^_^: 稍等一下 我过一眼 这段代码

blurs | 园豆:660 (小虾三级) | 2018-09-20 10:48

@Faith^_^: 。。。 我完全没看懂这是撒。。

你成功的击败了我。。 有页面么话说 注释。。。

blurs | 园豆:660 (小虾三级) | 2018-09-20 10:53

噗 我大概懂了。。 不过说句实话 这代码 还要练练。。。

blurs | 园豆:660 (小虾三级) | 2018-09-20 10:59

@Faith^_^: btns = $(cha.btnsId).children;
conts = $(cha.contsId).children;
前面+ var btns = $(cha.btnsId).children; var conts = $(cha.contsId).children;

也许就好了。。

blurs | 园豆:660 (小虾三级) | 2018-09-20 11:03

@Faith^_^: 话说 你这要是重复了咋办。。 比如table里面有个text标签。。

blurs | 园豆:660 (小虾三级) | 2018-09-20 11:07

@blurs: 没毛病是因为变量声明的问题,当初我找的时候大概找到了哪里的问题没往这里考虑;我这个代码贴的也有点毛病,我自己还封装了个包,有点是用的自己包里的。。。。

少_年 | 园豆:119 (初学一级) | 2018-09-20 11:52
其他回答(1)
0

I didn't try to verify your code logic, I just made some comments about your code habits.

 

First of all,  I find that you don't have the habit of good naming variables.

  You should try to understand the differences between the 2 naming methods of the "non-variable declaration symbol a = 1; " and "declare in var var a = 1; ".

  By the way, in ECMAScript 6 , there are 2 new ways to declare variables with  let  and  const .

 

Second, you don't understand how different variables are declared, what kind of scope and life cycle are brought to the variables.

收获园豆:10
写代码的相声演员 | 园豆:517 (小虾三级) | 2018-09-19 19:24

Thanks for your reply.
first I don't think I need a constant brightness here,so i don't use const ;
secondly i think var can define global and local variables,so I don‘t use let.
emmm,The life cycle is a bit fuzzy。

支持(0) 反对(0) 少_年 | 园豆:119 (初学一级) | 2018-09-20 08:50

神奇的人,你为什么要说英文,明明可以说中文。。。。。

支持(0) 反对(0) 少_年 | 园豆:119 (初学一级) | 2018-09-20 11:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册