2017-05-12 11 views
0

この時点で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(); 

    }); 
にこのqololblクリック機能をintializeするどのように機能していませんありがとうございます。

が私を助けて

+1

$( "qololbl")を試しましたか?document.readyでトリガー( 'click')しましたか? –

+1

@KhanjanBhattありがとうトリガー私のために働いて –

答えて

1

あなたがすることができますクリックイベント用クレート別の関数を、その後、あなたはそれを呼び出すと、イベントリスナーのためにそれを使用することができます。

$(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 triggerも使用する際にエラーが発生していますか?

+1

レスポンスありがとうございますが、私はトリガーを試してみてくださいその時間をクリックしてください。ありがとうございました –

1

はあなたが意味するか:

 $(".qololbl").on('click', function(){ 

}) 
+1

クリックせずにクリックするとその機能全体が初期化されません。お返事ありがとう –