【问题标题】:changing of text color and image background color using css and javascript使用 css 和 javascript 更改文本颜色和图像背景颜色
【发布时间】:2010-01-19 11:58:20
【问题描述】:

我想编写一个脚本来更改单击时的文本颜色和图像颜色..在这里我想将外部样式表(我将创建)调用到函数..每种颜色都会有所不同。页面。这样当我单击橙色时,如果我单击红色,文本和图像背景应该变为橙色,它应该变为红色..任何人都可以帮助我解决..任何想法或建议...提前致谢。

【问题讨论】:

  • 你的英语很难翻译。看了3遍就放弃了。请用完整的单词写正常的句子,如有必要,请运行拼写检查器。祝你好运。

标签: javascript css


【解决方案1】:

将每种颜色定义为 CSS 中的一个类:

.red {
color: red;
}

.blue {
color: blue;
}

然后在你的 HTML 中设置一个点击属性:

<p onclick="javascript: this.setAttribute('class', 'red');">Click to make me red</p>
<p onclick="javascript: this.setAttribute('class', 'blue');">Click to make me blue</p>

这里没有描述优化 - 主要使用不显眼的 javascript - 但这应该给你一个开始。

【讨论】:

    猜你喜欢
    • 2018-12-25
    • 2019-02-06
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多