show()在Firefox中不起作用,但在Chrome中工作

问题描述:

所以我一直在摸索我的头一个小时,尝试不同的解决方案,搜索这个网站和互联网,我不明白为什么它不工作.. 我为我的网站创建了一个非常简单的邮箱。当用户输入另一个用户的名字时,会发送一个ajax请求来验证用户名是否存在。根据答案,带有文本的小图标会通知用户用户名存在(或不存在),并在用户名正确时启用发送按钮。 此代码在Chrome中正常工作,但我无法使其在Firefox中正常工作。那就是:show()在Firefox中不起作用,但在Chrome中工作

$.ajax(
 
{ 
 
\t type: 'POST', 
 
\t url: "ajax.php", 
 
\t data: { 'user_nick': nick }, 
 
\t success: function(answer) 
 
\t { 
 
\t \t if(isNaN(answer)) 
 
\t \t { 
 
\t \t \t $("#user-not-found").show(); 
 
\t \t \t $("#send-msg").attr("disabled", true).css("opacity", "0.5"); 
 
\t \t } 
 
\t \t else // returns user id if username exists 
 
\t \t { 
 
\t \t \t $("#user-found").show(); 
 
\t \t \t $("input[name=sendto_id]").val(answer); 
 
\t \t \t $("#send-msg").attr("disabled", false).css("opacity", "1"); 
 
\t \t } 
 
\t }, 
 
\t error: function(xmlhttprequest, textstatus, message) 
 
\t { 
 
\t \t alert('An error has occured, please try again later (status-> '+textstatus+')'); 
 
\t \t populateBugForm(location.href, textstatus, message); 
 
\t } 
 
});
<p style="height:35px;margin-top:0px;"> 
 
<span class="email-display-field">To : </span> 
 
<input id="sendto" type="text" size="25"> 
 
<span id="user-not-found" style="display:none;z-index:30;margin-left:10px;"> 
 
<span id="user-found" style="display:none;margin-left:10px;">

jQuery的功能是通过在#sendto模糊事件触发。 (“#user-found”)。show()和$(“#send-msg”)。attr(“disabled”,false).css(“opacity”,“1”)不起作用作为$(“#user-found”)。show()),但有趣的部分是该ID已正确插入$(“input [name = sendto_id]”).val(answer)。

不知道该怎么办...

谢谢!

+0

任何控制台错误? – SpYk3HH 2014-09-29 21:17:42

+3

嗯......你的代码片段应该如何在没有后端的情况下工作? – 2014-09-29 21:18:13

+0

另外,这个Ajax事件何时被触发? – SpYk3HH 2014-09-29 21:20:12

基本上是ALT方法不起作用。请,你可以试试这个:

$.ajax(
    { 
    type: 'POST', 
    url: "ajax.php", 
    data: { 'user_nick': nick }, 
    success: function(answer) 
    { 
     if(isNaN(answer)) 
     { 
      $("#user-not-found").show(); 
      $("#send-msg").prop("disabled", true).css("opacity", "0.5"); 
     } 
     else // returns user id if username exists 
     { 
      $("#user-found").show(); 
      $("input[name=sendto_id]").val(answer); 
      $("#send-msg").prop("disabled", false).css("opacity", "1"); 
     } 
    }, 
    error: function(xmlhttprequest, textstatus, message) 
    { 
     alert('An error has occured, please try again later (status-> '+textstatus+')'); 
     populateBugForm(location.href, textstatus, message); 
    } 
});