javascript函数在firefox中工作,但在google chrome中不工作
我已经做了一个简单的功能,它在FireFox中工作得很好,但在google chrome中却没有。它给出了hide()函数的问题,并显示加载图像,函数的其余部分工作正常javascript函数在firefox中工作,但在google chrome中不工作,javascript,hide,show-hide,Javascript,Hide,Show Hide,我已经做了一个简单的功能,它在FireFox中工作得很好,但在google chrome中却没有。它给出了hide()函数的问题,并显示加载图像,函数的其余部分工作正常 function setPrivacyToCustom(){ $("form#email_contacts_form #gmail_import_btn").unbind(); $("form#email_contacts_form #gmail_import_btn").click(function()
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;
}
函数添加加载图像(元素、位置、图像名称、宽度、高度)
{
图像名称=图像名称的类型!=“未定义”?图像名称:“加载\u small\u purple.gif”;
宽度=宽度的类型!=“未定义”?宽度:“0”;
高度=高度类型!=“未定义”?高度:“0”;
var unique_num=new Date().getTime();
var obj=“”;
元素同级(“span.loading”).remove();
如果(位置==“之前”)
{
$(obj).insertBefore(elem);
}
else if(位置==“之后”)
{
$(obj).插入后面(elem);
}
返回唯一的_num;
}
上面的代码在fire fox中运行得很好,但在google chrome中却没有:(这是因为async:false发生的。因为当我使我的ajax调用asynchronous false时,它停止了将要发生的其他事件。在编写这样的代码之前,我应该知道asyn:false的正确实现。感谢@sunny,@ashish kumar的帮助。检查控制台中的错误。这可能会帮助您跟踪发生的位置您的代码正在中断。当我在console@ashishkumard中编写相同的代码时,它工作得非常正常。不要写任何东西,只需检查加载时的错误。我相信任何变量都会出现
null
或未定义的问题,正如您所说的,从console运行该代码工作正常。必须有一个或多个变量对象可能不受Chrome支持。创建并共享一个包含HTML和js函数的提琴。