English 中文(简体)
当正文箱活跃时,“加强”关键词指束字节功能
原标题:"Enter" key calls a javascript function when textbox is active

我有一个文字箱和一个 but子。

<div class="TextField Large">
    <input type="text" name="q" id="SearchBox" />
</div>
<div style="height: 40px; text-align: right; position: absolute; top: 0px; right: 0px;">
    <input type="button" value="Search" class="Button" onclick="Search()" />
</div>

基本上,在案文箱中,当你点击 Java子的“搜索台”功能时,请打电话<代码>Search()。

我怎么能补充一下,当用户在关键板上进入文字和新闻“加强”时,搜查就会被执行?

最佳回答
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function Search(){
    alert("search!");
    //search logic
    return false;
}
</script>
</head>
<body>
    <form onsubmit="return Search()">
        <input type="text" name="q" />
        <input type="submit" value="Search" />
    </form>
</body>
</html>

这一切

问题回答

第一,增加一个表格(无论 Java的字本如何,这都应有一个服务器的附带落差)。

第二: 将纽伦改为纽伦。

第三,将 Java改成表格,提交活动,而不是按纽伦的客户活动。

输入表格时,应自动提交表格。

否则:

$( your form ).keyup(function(e) {
  if(e.which == 13) $(this).submit();
});

我建议你改变ton子,以分类“提交书”,但为了自动发挥作用,则在提交活动时使用你的搜索码。

$( your form ).submit(function() {
  // your search code
}
$( #textbox ).keypress(function(event){
   var keycode = (event.keyCode ? event.keyCode : event.which);
   if(keycode ==  13 ){
      alert( You pressed a "enter" key in textbox );    
   }
});

希望这将有助于你。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签