jquery文件就绪函数触发两次 [英] jquery document ready function firing twice

查看:78
本文介绍了jquery文件就绪函数触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是$(文档).ready(function(){})触发两次。我已经检查过js文件是否在任何页面中都被链接了两次。但这不是问题。我已经尝试过变量并将其值初始设置为'false',然后在$(document).ready中将其设置为'true'。请从下面的代码中查看。



My problem is $(document).ready(function(){}) is firing twice. I have already checked whether the js file is linked twice in any page or not.but it is not the issue. I have already tried with a variable and set it's value initially to 'false' and then set it to 'true' inside $(document).ready. Please check from the code bellow.

var _DONE = false;

$(document).ready(function () {    
    if (_DONE == true) {           
        return;
    }  
    _DONE = true;
    InitUserAllocationRoleDD();
    var grid = $("#CWUsersAllocationGrid").data("kendoGrid");
    grid.bind("dataBound", function (e) { setGeneralGridHeight('CWUsersAllocationGrid') });
});





这段代码也不起作用。



实际代码:





This piece of code is also not working.

Actual Code:

 $(document).ready(function () {
    InitUserAllocationRoleDD();
    var grid = $("#CWUsersAllocationGrid").data("kendoGrid");
    grid.bind("dataBound", function (e) { setGeneralGridHeight('CWUsersAllocationGrid') });
});

function InitUserAllocationRoleDD() {
    GetDomainUsers();
    $('#cwallocationrole').unbind('change');
    $('#cwallocationrole').on('change', function () {
        if ($(this).find('option:selected').text() == '--Select--') {
            DomainNameSelector.val("");
            SequenceNumberSelector.val("");
            UserDefinedTextSelector.val("");
            return false;
        }
        selectedvalue = $(this).val();
        SelectedText = $(this).find('option:selected').text();
        SplitValue = selectedvalue.split("_");
        SplitText = SelectedText.split(":");
        $('#DomainName').val(SplitValue[1] + "_");
        $('#SequenceNumber').val("_" + SplitValue[2]);
        $('#UserDefinedText').val('');
    });
}

推荐答案

(文档).ready(function(){})触发两次。我已经检查过js文件是否在任何页面中都被链接了两次。但这不是问题。我已经尝试使用变量并将其值初始设置为'false',然后在
(document).ready(function(){}) is firing twice. I have already checked whether the js file is linked twice in any page or not.but it is not the issue. I have already tried with a variable and set it's value initially to 'false' and then set it to 'true' inside


(document).ready中将其设置为'true'。请从下面的代码中查看。



(document).ready. Please check from the code bellow.

var _DONE = false;


document )。ready( function (){
if (_DONE == true ){
return ;
}
_DONE = true ;
InitUserAllocationRoleDD();
var grid =
(document).ready(function () { if (_DONE == true) { return; } _DONE = true; InitUserAllocationRoleDD(); var grid =


这篇关于jquery文件就绪函数触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆