客家网络
学习技术、应用技术、创造价值
2007年8月29日
jQuery的简单应用-实现文本框获取焦点时改变样式
jQuery官方网站:
http://jquery.com/
功能实现:
用户在输入文字时,如果能高亮显示正在输入的那个文本框的话,会更人性化些,下面就使用jQuery来实现。
实现原理:
在document加载完成后(ready),添加input的focus和blur事件,并进行增加和删除样式的操作。
代码示例:
1
<
html
>
2
<
head
><
title
></
title
>
3
<
style
type
="text/css"
>
4
.redBack
{
}
{
5
color
:
white
;
6
background
:
red
;
7
border
:
2px solid black
;
8
}
9
</
style
>
10
<
script
language
="javascript"
src
="jquery-1.1.4.js"
type
="text/javascript"
></
script
>
11
<
script
language
="javascript"
>
12
$(document).ready(
function
()
{
13
$('input').focus(
function
()
{
14
$(
this
).addClass('redBack');
15
//
alert("hello");
16
}
);
17
18
$('input').blur(
function
()
{
19
$(
this
).removeClass('redBack');
20
}
);
21
}
);
22
</
script
>
23
</
head
>
24
<
body
>
25
<
input
type
="text"
value
="hello,shanzhu"
id
="myText"
>
26
<
input
type
="text"
value
="hello,shanzhu"
id
="myText2"
>
27
<
input
type
="text"
value
="hello,shanzhu"
id
="myText3"
>
28
<
input
type
="text"
value
="hello,shanzhu"
id
="myText4"
>
29
<
input
type
="text"
value
="hello,shanzhu"
id
="myText5"
>
30
<
input
type
="text"
value
="hello,shanzhu"
id
="myText6"
>
31
</
body
>
32
</
html
>
说明:
$(this)表示正在操作的对象。
posted @ 2007-08-29 13:15 客家网络 阅读(1688) 评论(1)
编辑
导航
博客园
首页
新随笔
联系
订阅
管理
公告
发布“图片水印工具”beta版本,欢迎使用,并提出意见与建议。
昵称:
客家网络
园龄:
6年3个月
粉丝:
0
关注:
0
<
2007年8月
>
日
一
二
三
四
五
六
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
统计
随笔 - 14
文章 - 0
评论 - 12
引用 - 0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
我的标签
IE7
(1)
滚动条
(1)
Dotfuscator
(1)
混淆
(1)
WebService
(1)
随笔分类
(12)
.NET2.0技术(6)
(rss)
MonoRail(1)
(rss)
软件发布(1)
(rss)
杂项技术(4)
(rss)
随笔档案
(14)
2008年11月 (1)
2008年10月 (1)
2007年11月 (2)
2007年10月 (2)
2007年9月 (1)
2007年8月 (2)
2006年8月 (1)
2006年5月 (3)
2005年11月 (1)
最新评论
阅读排行榜
评论排行榜
推荐排行榜