按下输入键时表单不提交

时间:2016-09-27 00:54:41

标签: javascript jquery html5

当我按下搜索按钮时,我得到的结果很好。但是,当我按下回车时,我希望能够搜索。

问题是,当我按回车键时,只需重新加载该地点即可转到displaylist()。我怎样才能做到这一点?

我在下面有以下代码html和JS。

HTML

<div class="input-group">
             <span class="input-group-btn">
               <button id="basic-search" class="btn btn-default " type="button" > <span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
           </span>              
           <input type="text"  id="basicsearchVal" class="form-control" placeholder="Enter a Ticker Symbol,CERT, BHCor a fragment of a Bank Name,." autocomplete="on">

</div>

JS

$(document).ready(function () {

        var newURL;
        var SearchData;       
        var detailPageUrl ="summary.html";   
        var mydata;

        displaylist(detailPageUrl,mydata,newURL);

        $("#basicsearchVal").keydown(function(e) {
            if (this.value != '') {
               console.log( "this.value keydown " +this.value);
                $(".search-result").jqGrid('GridUnload');
                var searchInput = $("#basicsearchVal").val()
                $("#pageTitle").html("Search Result(s) for <span class='text-primary'>" +searchInput+ "</span>")
                $( "#watchlist-b").remove();
                $("#watchList-b1").remove();
                $("#watchList-b2").remove();
                SearchData =newURL +"/services-monitor/GetQuickSearch?searchString="+searchInput;
                console.log("SearchData " +SearchData);
                displaySearchResult(detailPageUrl,SearchData,mydata); 

                jQuery(".search-result").trigger("reloadGrid");

            } else {
                 console.log( "Please enter a Name to search" +this.value);
            }
        });





    });

1 个答案:

答案 0 :(得分:2)

将按钮类型更改为按钮标记中的“提交”。