第一种:(文本框获取焦点后,它的颜色会有所变化,当失去焦点的时候,恢复为原来的样子)

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<style type="text/css">
input:focus ,textarea:focus{
border: 1px solid #f00;
background: #fcc;
}
</style> <body>
<form action="#" method="POST" id="regForm">
<fieldset>
<legend>个人基本信息</legend>
<div>
<label for="username">名称:</label>
<input id="username" type="text">
</div>
<div>
<label for="pass">密码:</label>
<input id="pass" type="password">
</div>
<div>
<label for="msg">详细信息:</label>
<textarea id="msg"></textarea>
</div> </fieldset>
</form> </body>
</html>

只不过IE中不兼容

第二种IE兼容:

 <html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<style type="text/css"> .focus{
border: 1px solid #f00;
background: #fcc;
}
</style>
<script type="text/javascript">
$(function(){
$(":input").focus(function(){
$(this).addClass("focus")
}).blur(function(){
$(this).removeClass("focus");
})
}) </script>
<body>
<form action="#" method="POST" id="regForm">
<fieldset>
<legend>个人基本信息</legend>
<div>
<label for="username">名称:</label>
<input id="username" type="text">
</div>
<div>
<label for="pass">密码:</label>
<input id="pass" type="password">
</div>
<div>
<label for="msg">详细信息:</label>
<textarea id="msg"></textarea>
</div> </fieldset>
</form> </body>
</html>

jquery获取和失去焦点改变样式的更多相关文章

  1. javascript和jquery 移除事件 和 改变样式

    javascript移除事件: document.getElementById("word").onmouseover = null; javascript改变样式: docume ...

  2. 问题:关于坛友一个获取text内容并改变样式的实现

    需求:点击button获得input框中选中的内容,让选中的内容变红, 实现:代码如下 1: <!DOCTYPE HTML> 3: <head> "content-t ...

  3. jQuery实现单击某个标签改变样式

    1.HTML代码,如下图: <p class="sc_member_recharge_form"> <span class="selected" ...

  4. jquery获取焦点和失去焦点事件代码

    input失去焦点和获得焦点 鼠标在搜索框中点击的时候里面的文字就消失了. 我们在做网站的时候经常会用到搜索框的获得焦点和失去焦点的事件,因为懒,每次都去写非常的烦,于是就一劳永逸,遇到类似情况就来调 ...

  5. js/jquery获取文本框的值与改变文本框的值

    我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtb ...

  6. jquery的blur之后,focus获取不到焦点的解决办法

    一:很多童鞋可能会遇到这种情况: jquery的blur之后,focus获取不到焦点. 二:使用场景: 用户填写信息的时候,若邮箱为空,则提示 请填写邮箱,并将光标置于填写邮箱的文本框里,方便用户的再 ...

  7. jQuery获取CSS样式中的颜色值的问题

    转自:http://blog.csdn.net/cwj649956781/article/details/23261529 jQuery获取CSS样式中的颜色值的问题,不同浏览器格式不同的解决办法,需 ...

  8. jQuery的input 失去焦点之后,不能再获取到焦点

    今天写了一个字段唯一性校验功能,验证设备仪器编号唯一,当输入编号之后 ,点击其他,失去焦点后,后台验证唯一,有过此编号,就给出提示,重新填写. 当使用ie时候,获取焦点正常 ,但是使用火狐就获取不到焦 ...

  9. jQuery入门(2)使用jQuery操作元素的属性与样式

    jQuery入门(1)jQuery中万能的选择器 jQuery入门(2)使用jQuery操作元素的属性与样式 jQuery入门(3)事件与事件对象 jQuery入门(4)jQuery中的Ajax()应 ...

随机推荐

  1. C# 设计模式 - 单例模式 演示

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. C# for循环①护栏长度 ②广场砖面积 ③判断闰年平年

        // static void Main(string[] args)         { const double PI = 3.14;             const int BAR_U ...

  3. [stack]Evaluate Reverse Polish Notation

    Total Accepted: 55722 Total Submissions: 249668 Difficulty: Medium Evaluate the value of an arithmet ...

  4. ubuntu 开启 rewrite 模块

    1.sudo a2enmod rewrite 开启Rewrite模块 (停用模块,使用 a2dismod) 2. 在/etc/apache2/ 修改apache2.conf 文件中把AllowOver ...

  5. Struts2 注解(转)

    转自:http://blog.csdn.net/wwwqvod/article/details/6214431 也叫Zero Configuration(零配置),它省去了写xml文件的麻烦,可以直接 ...

  6. QStringList不是简单重命名的便利类,而是提供了额外的函数,比如sort和join等等

    以前一直以为就是重命名而已,原来还不是.QT真伟大,方便到家了.该有的,全都有现成的.

  7. Oracle数据导入导出imp/exp(转)

    在oracle安装目录下有EXP.EXE与IMP.EXE这2个文件,他们分别被用来执行数据库的导入导出.所以Oracle数据导入导出imp/exp就相当与oracle数据还原与备份. 一.Oracle ...

  8. logstash 操作redis

    在实际应用中,Logstash进程会被氛围两个不同的角色. 运行在应用服务器上的尽量减轻运行压力,只做读取和转发,这个角色叫做shipper 运行在独立的服务器上完成数据解析处理,负责写入到Elast ...

  9. linux md5 加密字符串和文件方法

    linux md5 加密字符串和文件方法 MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5全称是报文摘要算法(Message-Digest Algorithm 5),此算法对任意 ...

  10. tracker-store and tracker-miner-fs eating up my CPU on every startup

    Tracker is a synergy of technologies that are designed to provide a highly sophisticated, innovative ...