简体   繁体   English

如何使用触发器等在准备就绪的文档上初始化我的功能?

[英]how to initialize my function on document ready using trigger etc..?

when qololbl mouse click at that time autocomplete function working perfect but how to initialize this function on document ready without qololbl click. 当qololbl鼠标单击时,自动完成功能可以正常工作,但是如何在没有qololbl单击的情况下在文档就绪时初始化此功能。

i tried to put this code in document ready $('.qololbl').click() at that time click function working but autocomplete is not working so how to intialize this qololbl click function on document ready 我试图将这段代码放在文档就绪$('。qololbl')。click()中,单击功能可以正常工作,但自动填充功能无法正常工作,因此如何在文档就绪时初始化此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();

    });

thanks in advance. 提前致谢。

help me 帮我

Do you mean: 你的意思是:

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

})

You can crate a separate function for the click event, and then you can call it and also use it for event listener. 您可以为click事件创建一个单独的函数,然后可以调用它并将其用于事件侦听器。

 $(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 should also work, are you getting any error when using it? jQuery trigger也应该起作用,使用它时会出现任何错误吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何编写单个 Jquery 函数来触发文档更改和就绪事件 - How to write a single Jquery function to trigger on document change and ready events Jquery 触发器 function 未准备好文档 - Jquery Trigger function not working with document ready 如何在document.ready中驻留的函数中重新初始化值? - How do I re-initialize values in a function resides in document.ready? 如何替换$(document).ready函数? - How to replace $(document).ready function? 如何在准备好的文档中返回函数? - How to return function in document ready? 在ajax和文档准备好后,Rails最好的初始化Javascript函数的方法 - Rails best way to initialize function in Javascript after ajax and document ready 使用$(function()与使用$(document).ready(function(){ - Using $(function () Versus using $(document).ready(function () { 我的文档.ready功能上的jQuery块无法正常工作 - Jquery Block on my document .ready function not working 在 jQuery 中对 var 编号进行任何更改后,如果 {} function 如何触发? 而不仅仅是在准备好文件时触发 - How to trigger if {} function after any change to var number in jQuery? rather than only firing on document ready JQuery 使用传递的参数值通过 $(document).ready 初始化页面 - JQuery Using passed parameter value to initialize a page via $(document).ready
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM