首页 > 代码库 > JS回车键处理

JS回车键处理

HTML

 <input type="text" id="keyword" name="keyword" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) search(document.getElementById(‘keyword‘).value);" value=http://www.mamicode.com/"@WorkContext.SearchWord" />
View Code

JS

//搜索function search(keyword) {    if (keyword == undefined || keyword == null || keyword.length < 1) {        alert("请输入关键词");    }    else {        window.location.href = "/Catalog/Search?keyword=" + encodeURIComponent(keyword);    }}
View Code

路由

  //搜索路由            routes.MapRoute("Search",                            "search",                            new { controller = "Catalog", action = "Search" },                            new[] { "BrnShop.Web.Controllers" });
View Code

 

JS回车键处理