博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

JQuery文本框焦点获得,失去控制![抄袭VS备忘]

Posted on 2009-02-06 09:38  菠萝  阅读(5131)  评论(0编辑  收藏  举报
 
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type="text/css" media="screen">
body { font: .9em/1.5 "Lucida Grande", "Trebuchet MS", "Bitstream Vera Sans", Verdana, Helvetica, sans-serif; }
form { width: 20em; margin: 4em auto; }
dt { clear: left; float: left; }
dd { clear: right; margin-left: 6em; }
input, textarea { width: 12em; border: 1px solid #ccc; }
input:focus, textarea:focus { border: 1px solid #f00; background: #fcc; }
.ie_hover { background: #ffc; }
.ie_focus { border: 1px solid #f00; background: #fcc; }
</style>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
    <title>JQuery文本框焦点获得,失去控制! </title>
    <script type="text/javascript" src="jquery.js"></script>
</head>


<script language="javascript">
$(document).ready(function(){
if ($.browser.msie){
// $("input[@type='text'], input[@type='password'], textarea").focus(function(){$(this).addClass("ie_focus")}).blur(function(){$(this).removeClass("ie_focus")});

$("#name").focus(function(){$(this).addClass("ie_focus")}).blur(function(){$(this).removeClass("ie_focus")});
$("#name").focus(function(){$(this).addClass("ie_focus")}).blur(function(){name=$("#name").val();alert(name);});

$("#username").focus(function(){$(this).addClass("ie_focus")}).blur(function(){n = $("#<%= username.ClientID %>")[0]; alert(n.value);});//服务器端控件元素
}
})
</script>

<body>
<form runat="server">
<dl>
   <dt>Name: <dt>
   <dd><input type="text" id="name"/></dd>
        <asp:TextBox ID="username" runat="server"></asp:TextBox>
               
   <dt>Password: <dt>
   <dd><input type="password" id="password"/></dd>
   <dt>Textarea: <dt>
   <dd><textarea id="content"></textarea></dd>
</dl>
</form>
</body>
</html>