嘿,我有一個吼吼箱的jQuery/ajax代碼,我遇到的問題是,當我有輸入消息周圍的窗體標籤和提交按鈕的HTML代碼,在按下輸入鍵入正在重新加載頁面的消息框,這在其他瀏覽器中不會發生,所以我刪除了表單,因爲它不是必需的,而且Enter鍵現在在IE中提交消息,但不在Chrome或Firefox中提交。有沒有辦法讓我可以同時進行onclick事件和輸入事件來糾正?此時一旦按鈕被點擊,按鈕被禁用2秒,然後renabled,我也需要這樣做,如果按下輸入按鈕。jquery shoutbox IE錯誤
我知道我有很多inline css for the shoutout box,但它現在只是一個測試版本,一旦它完成,我會整理它。
任何幫助,非常感謝。
I had the form tag like so
<form method="POST" action=""/>
<div id="shoutout" style="position:absolute; height:auto; overflow-x:hidden; overflow-y:hidden; float:right; right:10px; background-color:#121212; color:#FFFFFF; font-size:14px; width:305px; padding-left:1px; padding-right:1px; padding-bottom:1px; font-family: Arial, Helvetica, sans-serif;">
<h2>Shout Out!</h2>
<strong>Message:</strong>
<input type="text" id="message" name="message"/>
<input type="submit" id="submit" value="Submit"/>
<div id="messagecontainer" style="position:relative; height:240px; overflow-x:hidden; overflow-y:auto; background-color:#F5F5F5; color: #F6221D; font-size:12px; width:305px; margin-top:5px;">
<div id="shoutmessages" style="position:relative; word-wrap: break-word; padding-left:5px; width:auto; height:auto; overflow-y:hidden; overflow-x:hidden;">
</div>
</div>
</div>
//JQUERY AJAX CODE BELOW
<script type="text/javascript">
$(function(){
refresh_shoutbox();
setInterval("refresh_shoutbox()", 10000);
var running = false;
$("#message").keypress(function(e){
if (e.which == 13 && running === true){
return false;
}
});
$("#submit").click(function(){
if ($("#message").val() != ''){
running = true;
$("#submit").attr("disabled","disabled");
setTimeout(function(){
$("#submit").removeAttr("disabled")
running = false;
}, 2000);
}else{
return false;
}
var name = $("#name").val();
var message = $("#message").val();
var data = 'name=' + name + '&message=' + message;
$.ajax({
type: "POST",
url: "shout.php",
data: data,
success: function(html){
$("#shoutmessages").slideToggle(0, function(){
$(this).html(html).slideToggle(0);
$("#message").val("");
});
}
});
return false;
});
});
function refresh_shoutbox(){
var data = 'refresh=1';
$.ajax({
type: "POST",
url: "shout.php",
data: data,
success: function(html){
$("#shoutmessages").html(html);
}
});
}
由於某種原因,在IE和Chrome和Firefox中,我不能通過按回車鍵提交消息,只能通過點擊提交按鈕,我認爲它在IE中工作,但回車鍵不工作其中的實際。不要從這些錯誤。 – user970117
那麼在你的代碼中,當按下回車鍵時,你指示它'返回false; ',你期望它做什麼? – element119
多數民衆贊成只有當按鈕被禁用,它會返回false,因爲因爲var運行將被設置爲true。 – user970117