我有一个按钮,其原始颜色为红色,我希望它在聚焦时使用 Tab 键将其颜色更改为绿色,当您按 Enter 时,颜色应恢复为红色。
<div style="position: absolute; margin: 0; left: 0; bottom: 0">
<input class="button calculator large top-right-border transition" type="submit" />
</div>
.button.calculator{
background:red;
}
.button.calculator:focus{
background:green;
}
最佳答案
您可以使用 javascript 来实现这一点。
代码
HTML:
<div id="parent">
<button id="submit" onClick="functiong()">
</div>
Javascript:
<script>
functiong() {
$("#parent").on('click', '#submit', function () {
$("#submit").val("some value");
$("#submit").attr("id", "some id");
$("#submit").style.backgroundColor("#f47121");
});
}
</script>
关于javascript - 按回车后更改按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278728/