Visit Shenzhen, Shenzhen China, Shenzhen Travel Guide

Shenzhen Shopping - Visit Shenzhen's guide for the best shopping in Shenzhen.

Blog

GIS

Links

Recommend

Reference

常用链接

jQuery应用-实现文本框获取焦点时改变样式

功能实现:
用户在输入文字时,如果能高亮显示正在输入的那个文本框的话,会更人性化些,下面就使用jQuery来实现。
实现原理:
在document加载完成后(ready),添加input的focus和blur事件,并进行增加和删除样式的操作。
代码示例:

<html>
<head><title></title>
<style type="text/css">
     .redBack{}{
         color:white;
         background:red;
         border:2px solid black;
  }
</style>
<script language="javascript" src="jquery-1.1.4.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function(){
$('input').focus(function(){
    $(this).addClass('redBack');
//alert("hello");
});
$('input').blur(function(){
    $(this).removeClass('redBack');
});
});
</script>
</head>
<body>
<input type="text" value="hello,shanzhu" id="myText">
<input type="text" value="hello,shanzhu" id="myText2">
<input type="text" value="hello,shanzhu" id="myText3">
<input type="text" value="hello,shanzhu" id="myText4">
<input type="text" value="hello,shanzhu" id="myText5">
<input type="text" value="hello,shanzhu" id="myText6">
</body>
</html>

说明:
$(this)表示正在操作的对象。

Shenzhen Shopping - Visit Shenzhen's guide for the best shopping in Shenzhen.

posted on 2008-04-14 17:35 kaixin110 阅读(597) 评论(0)  编辑 收藏 网摘 所属分类: Web开发和设计




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 1153085




相关文章:

相关链接:
Shenzhen Shopping - Visit Shenzhen's guide for the best shopping in Shenzhen.