日期:2014-05-18  浏览次数:20355 次

为什么此重定向无效
文本框输入值以后,回车,为什么无法定向?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>无标题页</title>
  <script>
  function txtSearchEnter() {
  if (event.keyCode == 13) {
  document.location.href = "http://www.baidu.com"; 
  }
   
  }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <input type="text" onkeydown="txtSearchEnter()" />
  </div>
  <%--<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />--%>
  </form>
</body>
</html>


------解决方案--------------------
这是IE的Bug,你可以这样写解决
<input type="text" onkeydown="txtSearchEnter()" />
<input style="display:none" />

加一个无用的input