日期:2014-05-18 浏览次数:20459 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> <table border="0" cellpadding="0" cellspacing="0" width="100%" onkeydown="keyHandler();"> <tr> <td><input type="text" id="txt1" name="txt1" /></td> <td><input type="button" id="btn1" name="btn1" value="按钮1" onclick="javascript:btnHandler();"/></td> </tr> <tr> <td><input type="text" id="txt2" name="txt2" /></td> <td><input type="button" id="btn2" name="btn2" value="按钮2" onclick="javascript:btnHandler();"/></td> </tr> </table> <script language="javascript"> <!-- function btnHandler() { var e=event.srcElement; alert(e.value); } function keyHandler() { if(event.keyCode==13) { var e=event.srcElement; var txtID = e.id; var btnID = txtID.replace('txt','btn'); var oButton = document.getElementById(btnID); oButton.click(); } } // --> </script> </BODY> </HTML>