当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 使用jquery给input和textarea设定ie中的focus

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 使用jquery给input和textarea设定ie中的focus


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 561 ::
收藏到网摘: n/a

在浏览网站的过程中,我们经常可以看见当鼠标点击后样式改变的文本框和文本域,那么这种效果是如何实现的呢? 今天在做我们的表单提交部分的时候,遇到了这个问题,于是,用传说中的jquery就可以解决了.
这里主要说的是在IE下的focus的问题,因为在firefox中是支持
复制代码 代码如下:

input:focus
textarea:focus

在IE下:focus是无效的,所以,我们要在点击以后给input和textarea加上新的样式以配合实现:focus效果.
我们首先来看下效果:
来看下这个效果中的JS:
$(document).ready(
function(){if($.browser.msie){
$("input[@type='text'], input[@type='password'], textarea").focus(function() {$(this).css({background:"#FFFFF7"});})
$("input[@type='text'], input[@type='password'], textarea").blur(function() {$(this).css({background:"#fff"});})
}});
</script>

CSS这里这样定义:
input,textarea{border: 1px solid #CCC;}
input:focus,textarea:focus{background:#FFFFF7;}
这是jquery的一个很简单的应用,我也是初学,多多交流...