回車觸發事件

今天作一個需求,回車實現提交事件。javascript

代碼以下:java

<div class="select">
            
                    <input type="text" id= "loginform" name="search_content"  class="input01"></input>
                    <input type="button" class="input02"  name="search" value="搜索"></input>
            
            </div>
            <script>
                 $("#loginform").keydown(function(e){
                     var e = e || event,
                     keycode = e.which || e.keyCode;
                     
                     if (keycode==13) {
                      $("input[name='search']").trigger("click");

                     }
                }); 


                            
            </script>
            <script type="text/javascript">
    $(function() {
        $("input[name='search']").click(function() {

            var search_content = $.trim($("input[name='search_content']").val());

            if (!search_content)
            {
                alert("搜索內容不能爲空");
            }
            else
            {
                var url = '{function name="a_u" a="Index/index" b="act-search"}';
                url = url + "&search_content=" + search_content;
                window.open(url);
            }
        })
    })
</script>
相關文章
相關標籤/搜索