码迷,mamicode.com
首页 > 其他好文 > 详细

表单元素焦点的获取和失去

时间:2016-05-16 14:29:36      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

HTML:
<!DOCTYPE >

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
* {
/*margin: 0px;
padding: 0;*/
font-family: "微软雅黑", "arial", " sans-serif";
font-size: 16px;
}

body {
margin: 20px;
}

.focus {
border: 1px solid #f00;
background: #fcc;
}
</style>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>

<script type="text/javascript">
$(function () {
$(":input")
.focus(function () {
$(this).addClass("focus");
})

.blur(function () {
$(this).removeClass("focus");
})
});
</script>
</head>

<body>
<form>
<fieldset style="width: 370px;height: 136px;">
<legend>登录界面</legend>
<div>
<label for="username">用户:</label>
<input id="username" type="text"/>
</div>
<div>
<label for="pass">密码:</label>
<input id="pass" type="password"/>
</div>
</fieldset>
</form>

</body>

</html>

result:
技术分享

运行:
技术分享

HTML:
<!DOCTYPE >
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
* {
/*margin: 0px;
padding: 0;*/
font-family: "微软雅黑", "arial", " sans-serif";
font-size: 16px;
}

body {
margin: 20px;
}

.focus {
border: 1px solid #f00;
background: #fcc;
}
</style>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>

<script type="text/javascript">
$(function () {
$(":input").bind({
focus: function () {
$(this).addClass("focus");
},
blur: function () {
$(this).removeClass("focus");
}
})


});
</script>
</head>

<body>
<form>
<fieldset style="width: 370px;height: 136px;">
<legend>登录界面</legend>
<div>
<label for="username">用户:</label>
<input id="username" type="text"/>
</div>
<div>
<label for="pass">密码:</label>
<input id="pass" type="password"/>
</div>
</fieldset>
</form>

</body>

</html>


表单元素焦点的获取和失去

标签:

原文地址:http://www.cnblogs.com/theWayToAce/p/5497818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!