想写个点击那个 tab 时那个 tab 的下边框变橙色,但是 js 里不能写 - 符号,想问问这种情况该怎么解决
tab[i].onclick = function(){
tab[x].style.border-bottom = '0';
tab[this.index].style.border = 'lightsalmon solid 4px';
songContent[x].style.display = 'none'
songContent[this.index].style.display = 'block'
x=this.index
}
1
Jaosn 2020 年 8 月 13 日
这种功能根本不需要 JS
li :hover { border-bottom: 1px solid xxx; } |
2
lisianthus 2020 年 8 月 13 日 via iPhone
-后面的字母大写
|
3
hoyixi 2020 年 8 月 13 日 驼峰写法,backgroundColor
borderBottomStyle,borderBottomWidth,具体可以查 MDN |
4
shenyu1996 2020 年 8 月 13 日
border-bottom -> borderBottom
|
5
Curtion 2020 年 8 月 13 日 你把 style 对象打印出来看一看就知道都变成了小驼峰写法: borderBottom ;如果确实要用时请用['border-bottom']这种方式取属性值
|
6
lisianthus 2020 年 8 月 13 日 via iPhone @lisianthus tab[x].style.borderBottom = '0';
|
7
DoUSeeMe 2020 年 8 月 13 日
> tab[x].style['border-bottom'] = '0';
拿走不谢 另 驼峰 也可 |
8
zzx0403 2020 年 8 月 13 日
获取 dom 对象里的 style 找到想要的 key
|
9
Bluevect 2020 年 8 月 14 日 via Android
楼上驼峰正解 borderBottom
|
10
aaronlam 2020 年 8 月 14 日 JS 有两种读取属性的方法,
第一种:点语法,例如:foo.bar 第二种:中括号语法,例如:foo['bar'] 中括号语法,可以解决楼主你这种情况。另外针对你这种情况,还可以使用点语法属性名采用小驼峰即可。 |
11
shakaraka PRO 你这种需求只需要先定义好 class,然后用 classList 动态添加 class 名就能解决了的,你这把样式写 js 一堆乱
|
12
wi 2020 年 8 月 14 日
使用 TypeScript 你就会看到所有 Dom 属性的定义
|
13
PinkRabbit 2020 年 8 月 14 日
css 可解决,或者驼峰
|
14
dumbass 2020 年 8 月 14 日
动态切换 css class 更好吧
|
15
Doracis 2020 年 8 月 14 日 一般是选中加个 active 的 css class,然后定义.class{...}
|
16
azcvcza 2020 年 8 月 14 日
动态改 class 名就行了,把 css 风格和 js 硬赋值解耦,以后改就改 class 名,不用去翻 js 代码了
|
17
zhw2590582 2020 年 8 月 14 日
经验之谈,能用 css 解决的就不要用 js
|