Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery shoutbox IE错误_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript Jquery shoutbox IE错误

Javascript Jquery shoutbox IE错误,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,嘿,我有一些用于shoutbox的jquery/ajax代码,我遇到的问题是,在IE中,当我在html代码中的输入消息和提交按钮周围有表单标记时,在消息框中按enter键时,它正在重新加载页面,这在其他浏览器中没有发生,因此我删除了表单,因为它不需要,现在回车键是在IE中提交消息,而不是在chrome或firefox中。是否有一种方法可以同时使用onclick事件和enter事件来更正此问题?当点击按钮时,按钮被禁用2秒钟,然后重新激活,如果按下回车按钮,我需要这种情况也发生 我知道我有很多用于

嘿,我有一些用于shoutbox的jquery/ajax代码,我遇到的问题是,在IE中,当我在html代码中的输入消息和提交按钮周围有表单标记时,在消息框中按enter键时,它正在重新加载页面,这在其他浏览器中没有发生,因此我删除了表单,因为它不需要,现在回车键是在IE中提交消息,而不是在chrome或firefox中。是否有一种方法可以同时使用onclick事件和enter事件来更正此问题?当点击按钮时,按钮被禁用2秒钟,然后重新激活,如果按下回车按钮,我需要这种情况也发生

我知道我有很多用于shoutout框的内联css,但它目前只是一个测试版本,一旦完成,我会整理它

非常感谢您的帮助

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);
    }
    });
}
我有这样的表单标签
喊出来!
消息:
//jqueryajax代码如下
$(函数(){
刷新_shoutbox();
setInterval(“refresh_shoutbox()”,10000);
var running=false;
$(“#消息”)。按键(功能(e){
如果(e.which==13&&running==true){
返回false;
} 
}); 
$(“#提交”)。单击(函数(){
如果($(“#消息”).val()!=“”){
运行=真;
$(“#提交”).attr(“禁用”、“禁用”);
setTimeout(函数(){
$(“#提交”).removeAttr(“已禁用”)
运行=错误;
}, 2000);
}否则{
返回false;
}
var name=$(“#name”).val();
var message=$(“#message”).val();
变量数据='name='+name+'&message='+message;
$.ajax({
类型:“POST”,
url:“shout.php”,
数据:数据,
成功:函数(html){
$(“#shoutmessages”).slideToggle(0,function(){
$(this).html(html).slideToggle(0);
$(“#消息”).val(“”);
});
}
});    
返回false;
});
});
函数刷新\u shoutbox(){
变量数据='刷新=1';
$.ajax({
类型:“POST”,
url:“shout.php”,
数据:数据,
成功:函数(html){
$(“#shoutmessages”).html(html);
}
});
}

由于所有这些都是通过AJAX完成的,因此您可能会发现根本不包含
元素就更容易了

这样,您就避免了
中的表单元素出现的所有恼人的浏览器特定行为,比如在按下
时自动提交表单


您说过,当您在其他浏览器中删除它时,enter键不起作用-例如,您是否从Chrome或Safari JS调试控制台收到任何错误?

出于某种原因,在IE、Chrome和firefox中,我无法按enter键提交消息,只需单击submit按钮,我以为它在IE中起作用,但实际上enter键在任何一个IE中都不起作用。在你的代码中,当按下回车键时,你指示它返回false,您希望它做什么?只有当按钮被禁用时,它才会返回false,因为var running将被设置为true。我知道。但是,如果只有按下enter键时运行的代码返回false,为什么enter键会起作用?你应该保留它,并添加代码来调用
$(“#提交”)。单击()
。啊,好的,谢谢,对不起,我对Jquery很陌生,我该怎么做??。