2017-05-12 1 views
0

그 때 qololbl 마우스를 클릭하면 자동 완성 기능이 완벽하게 작동하지만 qololbl 클릭없이 문서에서이 기능을 초기화하는 방법. 트리거 등을 사용하여 문서에서 내 기능을 초기화하는 방법은 무엇입니까?

내가 문서 준비 $에서이 코드를 넣어 시도 ('. qololbl를'). 작업하지만 자동 완성 준비 문서에이 qololbl 클릭 기능을 초기화하기 방법을 그렇게 작동하지 않습니다 그 시간 클릭 기능에서()을 클릭

$(document).ready(function (e) {  

     $(".qololbl").click(function(){ 
       var garshunivalue = 0;   
       if($('#True').val() == "true") 
       {    
        if($('#defaultgarshuniid').val() > 0) 
        { 
         garshunivalue = $('#defaultgarshuniid').val(); 
        } 
       } 
       $("#qoloname").autocomplete({ 
        source: LiveUrl + "/api/Qolo/QoloList?garshunivalue="+garshunivalue, 
        select: function (event, ui) {     
         $("#qoloname").val(ui.item.Qolo_Name);       

         var searchtype1; 
         if(typeof $('input[name=radio-choice-t-6]:checked').val() == "undefined") 
         { 
          searchtype1 = 'qolo'; 
         } 
         else 
         { 
          searchtype1 = $('input[name=radio-choice-t-6]:checked').val(); 
         } 
         window.location.href = "index.html?term="+ui.item.Qolo_Name+ "&type=" + searchtype1;     
        }, 

        minLength: 0, 
        close: function(){ 
         $(this).blur(); 
        }}).focus(function(event, ui){ 
         $(this).autocomplete("#stanza", ""); 
        }); 

       $.ui.autocomplete.prototype._renderItem = function (ul, item) { 

        var re = new RegExp($.trim(this.term.toLowerCase())); 
        var qoloname = item.Qolo_Name.replace(re, "<span style='font-weight:600;color:#5C5C5C;'>" + $.trim(this.term.toLowerCase()) + "</span>"); 
        var garshuniname = item.Garshuni_Name.replace(re, "<span style='font-weight:600;color:#5C5C5C;'>" + $.trim(this.term.toLowerCase()) + "</span>"); 
         return $("<li></li>") 
          .data("item.autocomplete", item) 
          .append("<a>"+ "<div style='float:right;'>" + qoloname + "</div>" +"<div style='float:left;'>" + garshuniname + "</div>" + "</a>") 
          .appendTo(ul); 
       };   
      }); 

      $('.qololbl').click(); 

    }); 

미리 감사드립니다.

도움 나

+1

$ ("qololbl")을 (를) 사용하셨습니까? document.ready에서 트리거 ('클릭') 한 적이 있습니까? –

+1

@ KhanjanBhatt 고마워 방아쇠 나를 위해 일 –

답변

1

. 그것을 사용하는 경우 trigger도 작동합니다

$(document).ready(function(e) { 
    function initAutocomplete { 
    var garshunivalue = 0; 
    if ($('#True').val() == "true") { 
     if ($('#defaultgarshuniid').val() > 0) { 
     garshunivalue = $('#defaultgarshuniid').val(); 
     } 
    } 
    $("#qoloname").autocomplete({ 
     source: LiveUrl + "/api/Qolo/QoloList?garshunivalue=" + garshunivalue, 
     select: function(event, ui) { 
     $("#qoloname").val(ui.item.Qolo_Name); 

     var searchtype1; 
     if (typeof $('input[name=radio-choice-t-6]:checked').val() == "undefined") { 
      searchtype1 = 'qolo'; 
     } else { 
      searchtype1 = $('input[name=radio-choice-t-6]:checked').val(); 
     } 
     window.location.href = "index.html?term=" + ui.item.Qolo_Name + "&type=" + searchtype1; 
     }, 

     minLength: 0, 
     close: function() { 
     $(this).blur(); 
     } 
    }).focus(function(event, ui) { 
     $(this).autocomplete("#stanza", ""); 
    }); 

    $.ui.autocomplete.prototype._renderItem = function(ul, item) { 

     var re = new RegExp($.trim(this.term.toLowerCase())); 
     var qoloname = item.Qolo_Name.replace(re, "<span style='font-weight:600;color:#5C5C5C;'>" + $.trim(this.term.toLowerCase()) + "</span>"); 
     var garshuniname = item.Garshuni_Name.replace(re, "<span style='font-weight:600;color:#5C5C5C;'>" + $.trim(this.term.toLowerCase()) + "</span>"); 
     return $("<li></li>") 
     .data("item.autocomplete", item) 
     .append("<a>" + "<div style='float:right;'>" + qoloname + "</div>" + "<div style='float:left;'>" + garshuniname + "</div>" + "</a>") 
     .appendTo(ul); 
    }; 
    } 

    $(".qololbl").click(initAutocomplete); 
    initAutocomplete(); 
    //should also work 
    //$(".qololbl").trigger('click) 

}); 

jQuery를, 당신은 어떤 오류가있다?

+1

응답을 보내 주셔서 감사하지만 시도 할 때 클릭하십시오 그 시간 트리거 나를 위해 일하십시오. 고맙습니다 –

1

뜻 수행

당신은 상자 클릭 이벤트에 대한 별도의 기능을 할 수있는, 그리고 당신이 그것을 호출하고 또한 이벤트 리스너에 사용할 수
 $(".qololbl").on('click', function(){ 

}) 
+1

아무런 클릭도없이 전체 기능을 초기화하지 않고 클릭하십시오. 응답을 주셔서 감사합니다 –

관련 문제