css的属性名如果带中划线为什么不能通过javascript理改,高手帮帮忙!

panther8888 2006-05-18 10:07:17
网页中有如下内容:
<div id = 'test">test</div>
<input type = "button" name = "button1" value = "更改前景色" onclick = "test.style.color = 'red';" /input>
<input type = "button" name = "button2" value = "更改背景色" onclick = "test.style.background-color = 'green';" /input>
为什更改前景色可以而理改背景色却不行呢?请高手指点。
...全文
157 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
panther8888 2006-05-18
  • 打赏
  • 举报
回复
谢稿两大侠,结贴了。
panther8888 2006-05-18
  • 打赏
  • 举报
回复
是不是把连线和连线后边的字母一起转换成一个大写字母就行了啊?
ice_berg16 2006-05-18
  • 打赏
  • 举报
回复
所有带连线的属性都转成camelize的形式
background-color => backgroundColor
text-align => textAlign
hbhbhbhbhb1021 2006-05-18
  • 打赏
  • 举报
回复
<div id = "test">test</div>
<input type = "button" name = "button1" value = "更改前景色" onclick = "test.style.color = 'red';">
<input type = "button" name = "button2" value = "更改背景色" onclick = "test.style.backgroundColor = 'green';">

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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