如何设置input 的背景颜色

作者&投稿:唐祁 (若有异议请与网页底部的电邮联系)
怎么设置input 的背景颜色~

在Userlogin.asp文件中添加下列风格样式代码:
/* 文本框的CSS定义:对应CSS中的“INPUT”,这里为文本框的风格设置,可定义内容为背景、字体、颜色、边框等 */
Input
{
BACKGROUND-COLOR: transparent;
BORDER-BOTTOM: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid;
BORDER-RIGHT: #ffffff 1px solid;
BORDER-TOP: #ffffff 1px solid;

发送table{border-collapse:collapse;}table td {border: 1px solid #000000;padding: 2px 5px;}input.warning{border-color: red;}String.prototype.padLeft = function (len, charStr) {return new Array(len - this.length + 1).join(charStr, '') + this;}function changeBgColor(input){var rgbInput = document.getElementById("rgb");var redInput = document.getElementById("red");var greenInput = document.getElementById("green");var blueInput = document.getElementById("blue");var redValue = Number(redInput.value);var greenValue = Number(greenInput.value);var blueValue = Number(blueInput.value);if(redValue 255 || isNaN(redValue)){alert("red value invalid");redInput.className = "warning";return;}redInput.className = "";if(greenValue 255 || isNaN(greenValue)){alert("green value invalid");greenInput.className = "warning";return;}greenInput.className = "";if(blueValue 255 || isNaN(blueValue)){alert("blue value invalid");blueInput.className = "warning";return;}blueInput.className = "";document.body.style.backgroundColor = "#" + redValue.toString(16).padLeft(2, '0') + greenValue.toString(16).padLeft(2, '0') + blueValue.toString(16).padLeft(2, '0');} red:green:blue:

可以用input的css中background属性设置。

1、新建html文件,在body标签中,输入一个input标签,用浏览器打开这个文件,可以发现input标签的默认背景色是白色:

2、为了防止当前input背景色和其他input标签冲突,我们可以给当前input设置唯一id,这里用“demo”为例:

3、在head标签和body标签之间添加样式标签style,在style标签中,输入‘#demo {backgroung : red; }’,这里以红色背景色为例,此时浏览器中的input标签背景颜色变成了红色:

4、除了用css设置input的背景颜色,还可以用JavaScript动态设置input背景颜色。在body标签和html标签之间添加script标签,先获取元素的id,再获取背景颜色属性。如图所示,在script标签中输入“document.getElementById('demo').style.background = 'pink';”,这里以粉色为例,此时浏览器中的input标签背景颜色变成了粉色;



可以用input的css中background属性设置。

操作设备:戴尔电脑

操作系统:win10

操作软件:input

1、新建html文件,在body标签中,输入一个input标签,input标签的默认背景色是白色:

2、为了防止标签冲突,给当前input设置唯一id,这里用“demo”为例:

3、在head标签和body标签之间添加样式标签style,在style标签中,输入‘#demo {backgroung : red; }’,此时浏览器中的input标签背景颜色变成了红色:

4、在script标签中输入“document.getElementById('demo').style.background = 'pink';”,此时浏览器中的input标签背景颜色变成了粉色。



如何设置input 的背景颜色?
这样试了不对:background-color:red 如何设置input 的背景颜色?其中type为text

------解决思路----------------------
HTML code

<style>
input.text{background-color:red}
</style>
<input type="text" class="text">
<input type="text" style="background-color:blue">

------解决思路----------------------
学习....

------解决思路----------------------
楼主的环境问题吧!

------解决思路----------------------
HTML code
<style>
input.text{background-color:red}
</style>

<script>
function mm()
{
var a = document.getElementsByTagName("INPUT");
for(var i=0; i<a.length; i++) if(a[i].type=="text") a[i].className="text";
}
</script>

<body onload="mm()">

<input/>
<input/>

</body>

方案一:HTML code<style>
input.text{background-color:red}
</style>
<input type="text" class="text">
<input type="text" style="background-color:blue">
方案二:
XML/HTML code
<style>
input.text{background-color:red}
</style>

<script>
function mm()
{ var a = document.getElementsByTagName("INPUT");
for(var i=0; i<a.length; i++) if(a[i].type=="text") a[i].className="text"; }
</script>

<body onload="mm()">

<input/>
<input/>

</body>

在Userlogin.asp文件中添加下列风格样式代码:
/* 文本框的CSS定义:对应CSS中的“INPUT”,这里为文本框的风格设置,可定义内容为背景、字体、颜色、边框等 */
Input
{
BACKGROUND-COLOR: transparent;
BORDER-BOTTOM: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid;
BORDER-RIGHT: #ffffff 1px solid;
BORDER-TOP: #ffffff 1px solid;
COLOR: #ffffff;
HEIGHT: 18px;
border-color: #ffffff #ffffff #ffffff #ffffff; font-size: 9pt
}
这段代码是控制文本框样式,其中“BACKGROUND-COLOR: transparent;”,transparent 为CSS样式中控制背景色透明的语句。