【问题标题】:How do I stop the input form to change background color and text color when I input and submit something?当我输入和提交内容时,如何停止输入表单以更改背景颜色和文本颜色?
【发布时间】:2021-02-06 05:22:36
【问题描述】:
.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 的解决方案都可以。我希望表单颜色始终保持黑色。或者当您单击输入表单时,有没有办法阻止表单执行下拉建议?谢谢

I want the color to always be looking like the input form on the bottom, and not whitening up like the input form on top

【问题讨论】:

  • 请提供代码工作示例或图片
  • @noob 我回答你的问题了吗?
  • 抱歉回复晚了,图片已经在帖子里了。单击带有解释的链接。对不起,谢谢

标签: javascript css forms


【解决方案1】:

悬停效果

如果您不希望输入颜色在悬停时改变,请删除这段代码:

.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;
}

,从Form中移除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
}

【讨论】:

  • 抱歉没有回复。我忘了说我希望表格始终保持颜色 rgba(0,0,0,0.7)。当您输入表单时,它的颜色从 rgba(0,0,0,0.7) 变为白色,我正试图阻止它。我希望表单始终保持颜色 rgba(0,0,0,0.7)。感谢您的帮助,很抱歉没有及时回复。
猜你喜欢
  • 2021-03-07
  • 1970-01-01
  • 2014-07-17
  • 1970-01-01
  • 2018-12-25
  • 1970-01-01
  • 2021-12-06
  • 2020-09-17
  • 2013-05-13
相关资源
最近更新 更多