JQuery

검색 처리 방법 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>

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

군자는 기회가 없다고 불평하지 않는다. -에머슨

댓글 ( 0)

댓글 남기기

작성