gpt4 book ai didi

javascript 函数在 firefox 中工作但在 google chrome 中不工作

转载 作者:行者123 更新时间:2023-11-29 10:15:50 25 4
gpt4 key购买 nike

我做了一个简单的功能,它在 fire fox 中工作得很好,但在 google chrome 中却不行。它给 hide() 函数带来了问题并显示了加载图像,其余函数工作正常。

function setPrivacyToCustom(){
$("form#email_contacts_form #gmail_import_btn").unbind();
$("form#email_contacts_form #gmail_import_btn").click(function()
{
var current_album_id = $(this).siblings('input#selected_album_id').val();
$(this).hide();
var loading_img = addLoadingImage( $(this), "before", 'loading_medium_purple.gif',61, 32 );
var usersList = "";
var total = $("input[name='emails[]']:checked:enabled").length;
$("input[name='emails[]']:checked:enabled").each(function(index)
{
if (index === total - 1)
{
// this is the last one
usersList += $(this).attr('rel');
}
else
{
usersList += $(this).attr('rel')+",";
}
});
var thisss = $(this);
$.ajax({
async: false,
url : "/" + PROJECT_NAME + "profile/set-custom-privacy-and-viewers-for-album",
method : "POST",
data :{"custom_viewer" : usersList, "album_id":current_album_id},
type : "post",
dataType : "json",
success : function(jsonData)
{
if(jsonData == 1)
{
$("span#"+loading_img).remove();
$('div#gmail_popup').bPopup().close();
$("span#"+loading_img).remove();
$(thisss).fadeIn();
$(".alert-box").remove();
$(".alert-box1").remove();
$(".alert-box2").remove();
showDefaultMsg( " Your setting changes have been saved.", 1 );

}
else
{
alert("Some error has occured.Please select custom user again.");
}

}

});

});
}

以上是我写的代码

 $(this).hide();
var loading_img = addLoadingImage( $(this), "before", 'loading_medium_purple.gif',61, 32 );

这两行在按钮隐藏和加载图像出现的地方不起作用。

显示加载图片的函数如下

function addLoadingImage(elem, position, image_name, width, height)
{
image_name = typeof image_name !== 'undefined' ? image_name : "loading_small_purple.gif";
width = typeof width !== 'undefined' ? width : "0";
height = typeof height !== 'undefined' ? height : "0";

var unique_num = new Date().getTime();
var obj = "<span class = 'loading' id = '"+unique_num+"' ><table><tr><td style = 'width:"+width+"px; height:"+height+"px'><img src = '/" + PROJECT_NAME + "public/images/" + image_name + "' alt = 'Wait...' /></td></tr></table></span>";
elem.siblings("span.loading").remove();
if( position == "before" )
{
$(obj).insertBefore( elem );
}
else if( position == "after" )
{
$(obj).insertAfter( elem );
}
return unique_num;
}

上面的代码在 fire fox 中可以完美运行,但在 google chrome 中却不行:(

最佳答案

这是因为 async:false 。因为当我使我的 ajax 调用异步为 false 时,它​​停止了将要发生的其他事件。在编写这样的代码之前,我应该知道 asyn:false 的正确实现。感谢@sunny、@ashish kumar 的帮助。

关于javascript 函数在 firefox 中工作但在 google chrome 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22006951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com