[英]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.