javascript - 当我输入并提交内容时,如何停止输入表单以更改背景颜色和文本颜色?
问题描述
.button{
outline-color: rgba(0,0,0,0.7);
width:290px;
margin: 20px 10px 10px 5px;
height:80px;
font-size:44px;
color:orange;
background-color:rgba(0,0,0,0.7);
border: 0;
border-bottom:2px solid black;
cursor:pointer;
}
.button:hover{
background-color:rgba(0,0,0,0.7);
}
.button:focus{
background-color: rgba(0,0,0,0.7);
width: 300px;
}
<form action="" onsubmit="return submitMove()">
<label class="lable">First Coordinate</label>
<div><input class="button" type="text" id="currentCoordinate" onchange="backgroundColor: rgba(0,0,0,0.7)" onclick="clickInput()"></div>
<lable class="lable">Second Coordinate</lable>
<div><input class="button" type="text" id="moveToCoordinate" onchange="backgroundColor: rgba(0,0,0,0.7)" onclick="clickInput()"></div>
<button class="button" onclick="clickInput()">Submit move</button>
</form>
function clickInput() {
document.getElementById("currentCoordinate").style.backgroundColor = "rgba(0,0,0,0.7)"
document.getElementById("moveToCoordinate").style.backgroundColor = "rgba(0,0,0,0.7)"
}
我想要的是让输入字段根本不改变颜色。我根本做不到。任何需要 CSS 或 javascript 的解决方案都可以。我希望表单颜色始终保持黑色。或者当您单击输入表单时,有没有办法阻止表单执行下拉建议?谢谢
解决方案
悬停效果
如果您不希望输入颜色在悬停时更改,请删除这段代码:
.button:hover{
background-color:rgba(0,0,0,0.7);
}
选择效果
如果您不希望在选择时更改输入颜色,请删除这段代码:
.button:focus{
background-color: rgba(0,0,0,0.7); // Remove this line
width: 300px;
}
,onclick="clickInput()"
从表单中删除并删除功能 -
function clickInput() {
document.getElementById("currentCoordinate").style.backgroundColor = "rgba(0,0,0,0.7)"
document.getElementById("moveToCoordinate").style.backgroundColor = "rgba(0,0,0,0.7)"
}
输入变化效果
如果不希望输入框中的数据发生变化时输入颜色也发生变化,去掉这段代码:
onchange="backgroundColor: rgba(0,0,0,0.7)"
浏览器效果
这是浏览器添加的默认样式(大多数情况下为蓝色轮廓)以克服此问题:
.button:focus{
outline: none; // Add this line
}
推荐阅读
- java - 错误:针对 Android API 28 时找不到符号变量 CLIP_SAVE_FLAG
- jquery - 如何仅捕获文本但忽略带有元素的文本?
- xml - 如何将以下标签中的所有文本项收集到以名称为键、年份为值的字典中?
- c# - 报告查看器中的部分
- matlab - 有没有办法增加分散数据的数据密度?
- google-sheets - 一种在进行动态运行总计时维护单元格引用的方法
- python - 如何使用 BeautifulSoup 从网页中获取整个正文?
- dart - 通过比较 Dart 中的索引对列表进行排序
- reactjs - Axios 以某种方式缓存我的获取用户请求本机反应
- python - 如何使用 Beautiful Soup 4 抓取 HTML url 修复“AttributeError: 'Client' object has no attribute 'send_message'”