简体   繁体   English

按Enter键(不工作)或搜索按钮查询结果(工作)

[英]Query for Results by Enter Key(Not Working) or Search button(Working)

If I click the search button, the results are appearing on the screen properly. 如果单击搜索按钮,结果将正确显示在屏幕上。 I want the same result to occur also by typing in the text box and pressing the enter key. 我希望通过在文本框中输入并按Enter键也能得到相同的结果。 The problem is the results are not appearing when I press enter. 问题是当我按回车键时结果没有出现。 Anyone know how I can fix this. 任何人都知道如何解决这个问题。 Thanks 谢谢

Here is the code 这是代码

    <input id="address" type="text" value="Paramus, NJ" />
<input type="button" value="Search" onclick="codeAddress();" />
<div id="info"></div>
<div id="mdiv">
  <div class="mdiv">
    <div class="md">
    </div>
  </div>
</div>

Here is a fiddle with problem 这是一个问题的小提琴

Put the inputs into a form, put the listener on the form's submit listener, change the button to a submit button and remove its listener: 将输入放入表单,将监听器放在表单的提交监听器上,将按钮更改为提交按钮并删除其监听器:

<form onsubmit="codeAddress(); return false;" action="...">
  <input id="address" type="text" value="Paramus, NJ">
  <input type="submit" value="Search">
</form>

Since currently the page may not navigate anywhere, I've added return false to the listener. 由于目前页面可能无法在任何地方导航,因此我向侦听器添加了return false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM