javascript - 为什么 javaScript 中的字符串赋值不区分大小写?

标签 javascript css

我已经创建了一个简单的 html 页面,其中包含一个按钮,该按钮在单击时会改变其颜色:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<button onclick="if (this.style.backgroundColor == 'Red') {
        this.style.backgroundColor = 'Green'
    }
    else {
        this.style.backgroundColor = 'Red'
    }
     alert(this.style.backgroundColor)">
    ok
</button>
</body>
</html>

令我惊讶的是 alert(this.style.backgroundColor) 返回 red 而不是 Red为什么?有一个赋值 this.style.backgroundColor = 'Red' 并且在这个 Red 中以大写字母开头。

最佳答案

CSS 样式不会保存为文字字符串,它们会转换为样式的内部规范表示。颜色样式不区分大小写,规范表示为小写。

关于javascript - 为什么 javaScript 中的字符串赋值不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23215963/

相关文章:

javascript - jquery slider seiyera 只显示文本框

javascript - 如何为自动显示@domain.com 的电子邮件输入制作输入组件

javascript - 外部js文件/unobtrusive js不起作用,但控制台中没有错误

css - <span> 的垂直边框可以重叠吗?

javascript - 如何启用CSS光标:pointer (the hand symbol) in mobile/tablet browser (touch screen)

javascript - Ajax 请求完成后,jQuery 会关闭 TCP 连接吗?

html - css 类覆盖样式 html 片段

php - Codeigniter Controller 也没有加载 View 错误消息

html - 强制灵活容器内的 img 以更正比例

javascript - 使用 jQuery addClass 转换时出错