검색 처리 방법 url encoding 핵심 코드
var str=encodeURIComponent(sKeyword).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
jQuery 전체 코드
$(document).ready(function(){ //search $("#searchsubmit_top").click(function(){ if($("#s_top").val() ==''){ alert("검색어를 입력하세요."); $("#s_top").focus(); return false; }else{ var sKeyword=$("#s_top").val(); var str=encodeURIComponent(sKeyword).replace(/[!'()]/g, escape).replace(/\*/g, "%2A"); var act='/index.php/user/search/lists/s/'+str+'/page/1'; $("#site-searchform_top").attr("action", act).submit(); } }); $("#searchsubmit").click(function(){ if($("#s").val() ==''){ alert("검색어를 입력하세요."); $("#s").focus(); return false; }else{ var sKeyword=$("#s").val(); var str=encodeURIComponent(sKeyword).replace(/[!'()]/g, escape).replace(/\*/g, "%2A"); var act='/index.php/user/search/lists/s/'+str+'/page/1'; $("#site-searchform").attr("action", act).submit(); } }); }); function board_search_enter(form){ var keycode =window.event.keyCode; if(keycode==13){ $("#search_btn").click(); } } function board_search_enter_top(form){ var keycode =window.event.keyCode; if(keycode==13)$("#searchsubmit_top").click(); } </script>
html 폼
<!-- <form method="post" id="site-searchform" action="#"> --> <?php $attribute =array( 'method' =>'POST', 'id'=>"site-searchform" ); echo form_open('', $attribute); ?> <div> <input class="input-text" name="s" id="s" onkeypress="board_search_enter(document.s);" placeholder="Enter Search keywords..." type="text" /> <input id="searchsubmit" value="Search" type="submit" /> </div> </form> </div><!-- end site search --> </div>
댓글 ( 4)
댓글 남기기