您的位置:首页 > Web前端 > JQuery

jQuery之文本框得失焦点

2016-11-27 14:11 267 查看
html代码部分:

<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" rows="2" cols="20"></textarea>
</div>
</fieldset>
</form>
</body>


这里有两个input,一个textare框。

:input匹配 所有 input, textarea, select 和 button 元素。

jQuery代码部分:

<script type="text/javascript">
$(function(){
$(":input").focus(function(){
$(this).addClass("****");
}).blur(function(){
$(this).removeClass("****");
});
})
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: