<div class="codetitle"> <span><a style="CURSOR: pointer" data="98307" class="copybut" id="copybut98307" onclick="doCopy('code98307')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code98307"> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>JavaScript</title> <br><style type="text/css"> <BR>body { /* 对页面布局进行调整 */ <BR>background-color: #ccc; <BR>width: 960px; <BR>height: 50%; <BR>margin: 0px auto; <BR>} <BR></style> <br> <br> <br><script type="text/javascript" src="jquery-1.8.0.js"> <BR></script> <br><br>用户名:<input type="text" name="user" id="user"><br> <br>密 码:<input type="password" name="passwd" id="passwd"> <br><br><script type="text/javascript"> <BR>$("body") <BR>.css("margin-left",(($(document).width() - 1024) / 2) + "px") <BR>.css("overflow-x", "hidden"); <br><br>/* 只对id为passwd的控件绑定keypress事件 */ <BR>$("input[id='passwd']").bind("keypress", function(event){ <BR>if (event.keyCode == '13') { // 回车按键的代码 <BR>if (!$('#user').val() || !$('#passwd').val()) { // 检测用户名与密码是否为空 <BR> alert("用户名或密码为空,请重新输入!"); <BR> return; <BR> } <BR>alert("用户名为:" + $('#user').val() + ", 密码为:" + $('#passwd').val()); <BR>} <BR>}); <br><br></script> <br> <br> <br> </div> <br><img src="http://files.jb51.net/file_images/article/201307/201307251743502.gif?201362517444" alt="jQuery的控件及事件(输入控件及回车事件)使用示例_jquery" >