动态设置文本框颜色:

主要是利用javascript中的触发事件onfocus和onblur

<script language="javascript" type="text/javascript">
<!--
function myFocus(obj,color){ //判断文本框中的内容是否是默认内容 if(obj.value=="请输入收件人地址"){
obj.value="";
} //设置文本框获取焦点时候背景颜色变换
obj.style.backgroundColor=color;
} function myblur(obj,color){ //当鼠标离开时候改变文本框背景颜色
obj.style.background=color;
}

在input标签中:

<input type="text" name="username" id="username" onfocus="myFocus(this,'#f4eaf1')" onblur="myblur(this,'white')" value="请输入收件人地址"/>  

用上述简单方法可以做到文本框背景颜色的变换和提示信息的清除

———————————————————————————————————————————————————————————————————

动态设置字体颜色

<html>  

<body>
<script language="javascript" type="text/javascript">
function test(obj)
{
if( obj.value!="test" ){
document.getElementById("inputbox").className= "input_s1";
}else{
document.getElementById("inputbox").className = "input_s2";
}
}
</script>
<style>
.input_s1 {font-size:20;color:red; background-color:;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
.input_s2 {font-size:20;color:black; background-color:;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</style>
<center> <br>
<form method="get" action="returnpage.php" >
<input id="inputbox" type='text' class="input_s1" value="test" maxlength='300' size='40' name='qw' onclick="test(this)"/>
<input type="submit" value="搜一下">
<br>
</center>
</body>
</html>

—————————————————————————————————————————————————————————————————

自己修改的一个,功能:文本框默认字体浅色,获取焦点时候清空文本框,输入文字变黑色,失去焦点判断文本框,重新回到浅色字体

function test(obj)
{
if( obj.value!="CAS/NAME/CATALOG" ){
document.getElementById("productParam").value="";
document.getElementById("productParam").className="input_s2";
}else{
document.getElementById("productParam").value="";
document.getElementById("productParam").className ="input_s2";
}
} function onBluet(obj){
if(obj.value == ""){
document.getElementById("productParam").value="CAS/NAME/CATALOG";
document.getElementById("productParam").className ="input_s1";
}else{
document.getElementById("productParam").className ="input_s1";
}
} <style>
.input_s1 {font-size:20;color:#949494; background-color:;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
.input_s2 {font-size:20;color:black; background-color:;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</style> <input class="input_s1" id="productParam" name="productParam" onkeyup="enterLogin(event);" type="text" value="CAS/NAME/CATALOG" onclick="test(this)" onblur="onBluet(this)"/></td>

js动态设置输入框字体/颜色的更多相关文章

  1. 设置placeholder字体颜色

    /*设置placeholder字体颜色*/::-webkit-input-placeholder{ color: #FFF;}:-ms-input-placeholder{ color: #FFF;} ...

  2. pycharm 如何设置函数调用字体颜色

    一.pycharm 如何设置函数调用字体颜色 1.打开pycharm编辑器,file > settings > editor > color scheme > python & ...

  3. js动态设置padding-top遇到的坑

    我想通过js动态设置元素padding-top的百分比值:以下几种都是无法设置成功的: // setAttribute设置padding-top并且转换为百分比 imageBox.setAttribu ...

  4. poi生成excel整理(设置边框/字体/颜色/加粗/居中/)

    转: poi生成excel整理(设置边框/字体/颜色/加粗/居中/) 2016年12月02日 11:05:23 吃奶的牛 阅读数:34324   HSSFWorkbook wb = new HSSFW ...

  5. Android 设置TextView字体颜色

    设置TextView字体的颜色其实很简单,尤其是直接在XML文件中,可以直接通过textColor属性指定颜色值,达到设置文本颜色的效果:那在代码中如何动态设置字体的颜色值呢? 接下来,介绍如何通过J ...

  6. Dynamic CRM 2013学习笔记(二十八)用JS动态设置字段的change事件、必填、禁用以及可见

    我们知道通过界面设置字段的change事件,是否是必填,是否可见非常容易.但有时我们需要动态地根据某些条件来设置,这时有需要通过js来动态地控制了. 下面分别介绍如何用js来动态设置.   一.动态设 ...

  7. js动态设置窗体位置

    1设置登录框的js,动态设置高度等 <script> $(document).ready(function () { $() / + "px"); $("in ...

  8. python之设置控制台字体颜色

    # 设置控制台输出字体颜色 # 格式:\033[显示方式;前景色;背景色m # 采用终端默认设置:\033[0m # 红色字体 print('\033[1;31m') print('*' * 10) ...

  9. 【C#/WPF】Button按钮动态设置Background背景颜色

    学习笔记: 在XAML中给Button设置颜色大家都懂的,本篇只是记录用C#代码动态生成的按钮设置Background背景颜色. new一个Button,设置Background时可看到该属性类型是S ...

随机推荐

  1. UIButton 解析

    IOS之按钮控件--Button全解析及使用 转载自:forget  IOS开发中伴随我们始终的 最常用的几个空间之一 -- UIButton 按钮,对于button今天在此做一些浅析,并介绍下主流用 ...

  2. vpn探测

    root@bt:~# ike-scan -M -v 192.168.1.102 root@bt:~# sslscan 192.168.1.102

  3. Win7+QTP10.0+IE9无法识别对象的解决方法

    在WIN7和IE9环境下使用QTP10,会出现识别不了web对象的情况,具体表现为:添加对象,先打开对象库,再打开IE,点击Add object to local 后,出现白色手指,将其拖拉到百度首页 ...

  4. DataGridView很详细的用法

    DataGridiew用法总结 一.DataGridView 取得或者修改当前单元格的内容: 当前单元格指的是 DataGridView 焦点所在的单元格,它可以通过 DataGridView 对象的 ...

  5. Winform带dataGridview的Combox控件

    调用控件: public partial class Form1 : Form { public Form1() { InitializeComponent(); //---------------- ...

  6. 如何将CAD文件导入到Protel和PADS中

    一. 如何把CAD中的板框图纸导入到Protel中? a. 在CAD中单位设置为“毫米”,并做简单的处理,板框图是有合并还是分解都无所谓,另存为R12(*dxf)格式文件. b. 打开DXP,新建PC ...

  7. (中等) CF 576D Flights for Regular Customers (#319 Div1 D题),矩阵快速幂。

    In the country there are exactly n cities numbered with positive integers from 1 to n. In each city ...

  8. 什么是j2ee ??EJB与j2ee的关系?? 请看百度百科

    首先,EJB是j2ee的一部分. http://baike.baidu.com/link?url=SGmNOVWoaZ62WCjb7a_yzz-GBGsDT3jyFM1hsvv8ycAwusdmo_D ...

  9. 通过条件注释<!--[if IE]><!-->判断浏览器

    有时我们会在网站头部看到: <!--[if IE 7]> <![endif]--> 或者 <!--[if lt IE 9]> <![endif]--> ...

  10. JS实现标签页效果(配合css)不同标签下对应不同div

    显示页面tab.jsp </ div ></ body > </ html >   tab.css ul ,li { margin:0px; padding:0px ...