如何编辑 HTML 输入值颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7194141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:17:10  来源:igfitidea点击:

How to edit HTML input value colour?

htmlforms

提问by James

In my input field (text), I have a text which disappears once it is clicked. How can I make this text a shade lighter by editing its colour?

在我的输入字段(文本)中,我有一个文本,一旦点击它就会消失。如何通过编辑其颜色使此文本更亮?

Sorry, the code looks messy, I had to chop it up to show you.

对不起,代码看起来很乱,我不得不把它切碎给你看。

Thanks!

谢谢!

James

詹姆士

<form>
   <input type="text" name="search" size="35"    
    onclick="this.value='';"onfocus="this.select()"
    onblur="this.value=!this.value?'Job Title   
    e.g. Assistant Manager':this.value;"
    value="Job Title e.g. Assistant Manager" 
    style="background-color:white; border: 
    solid 1px #6E6E6E; height: 30px; font-size:18px; 
    vertical-align:9px"/>

   <input type="text" name="searchterm" size="35" 
    style="background-color:white; border: solid 1px #6E6E6E;
    height: 30px; font-size:18px; vertical-align:9px"/>

   <input type="image" src="but.tiff" alt="Submit" width="60">
</form>

回答by Bojan Devi?

Maybe something like this (just add your style):

也许是这样的(只需添加您的风格):

<input type="text" 
       size="35" 
       value="Job Title e.g. Assistant Manager" 
       style="background-color:white; 
              border: solid 1px #6E6E6E;
              height: 30px; 
              font-size:18px; 
              vertical-align:9px;color:#bbb" 
        onfocus="if(this.value == 'Job Title e.g. Assistant Manager') {
                    this.value = '';
                    this.style.color='#000';
                 }" />

<input type="text" 
       name="searchterm" size="35" 
       style="background-color:white; 
              border: solid 1px #6E6E6E;
              height: 30px; 
              font-size:18px; 
              vertical-align:9px" />

回答by Kelly Cook

You can add color in the style rule of your input: color:#ccc;

您可以在输入的样式规则中添加颜色: color:#ccc;

回答by James Allardice

You can change the CSS colorproperty using JavaScript in the onclickevent handler (in the same way you change the valueproperty):

您可以coloronclick事件处理程序中使用 JavaScript更改 CSS属性(与更改value属性的方式相同):

<input type="text" onclick="this.value=''; this.style.color='#000'" />

<input type="text" onclick="this.value=''; this.style.color='#000'" />

Note that it's not the best practice to use inline JavaScript. You'd be better off giving your input an ID, and moving your JavaScript out to a <script>block instead:

请注意,使用内联 JavaScript 并不是最佳实践。你最好给你的输入一个 ID,然后把你的 JavaScript 移到一个<script>块中:

document.getElementById("yourInput").onclick = function() {
    this.value = '';
    this.style.color = '#000';
}

回答by Joish

Please try this:

请试试这个:

<input class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-8 col-md-offset-2" type="text" name="name" value="" placeholder="Your Name" style="background-color:blue;"/>

You basically put all the CSS inside the style part of the input tag and it works.

你基本上把所有的 CSS 放在输入标签的样式部分,它就可以工作了。

回答by Vishal Singh

Add a style = color:black !important;in your input type.

style = color:black !important;在您的输入类型中添加一个。