首先,英语不是我的母语,如果我有任何错误,很抱歉。
在函数中有消息发送问题,我已经尝试过Jquery代码,但我不能修复它。
当我按回车键时,消息到达接收器,这很好。但是当我按下Shift和Enter时,消息再次到达接收器,我想在按下这两个键的时候创建新的线路。
Jquery代码:
$(document).ready(function() {
$('input#chat').bind('keydown', function(e) {
if(e.keyCode==13) {
// Store the message into var
var message = $('input#chat').val();
var id = $('#chat').attr('class');
if(message) {
// Remove chat errors if any
$('.chat-error').remove();
// Show the progress animation
$('.message-loader').show();
// Reset the chat input area
document.getElementById("chat").style.height = "25px";
$('input#chat').val('');
发布于 2015-03-21 12:17:17
你试过了吗?
if(e.shiftKey && e.keyCode==13){
// Don't fill
} else if(e.keyCode==13){
e.preventDefault();
// Store the message into var
var message = $('input#chat').val();
var id = $('#chat').attr('class');
if(message) {
........................
}发布于 2015-03-21 12:53:21
在这种情况下,当按下shift键时,布尔值会阻止代码运行。
var ShiftDown = false; //Is false when not being pressed, true when being pressed
$(document).ready(function() {
$('input#chat').keydown(function(e) {
if(e.which === 16) {
//Shift key is pressed
ShiftDown = true;
}else if(e.which === 13){
//Code will only run if Shift key is not pressed
if(ShiftDown === false){
// Store the message into var
var message = $('input#chat').val();
var id = $('#chat').attr('class');
if(message) {
// Remove chat errors if any
$('.chat-error').remove();
// Show the progress animation
$('.message-loader').show();
// Reset the chat input area
document.getElementById("chat").style.height = "25px";
$('input#chat').val('');
}
}
}
})
$('input#chat').keyup(function(e) {
if(e.which === 16){
//Shift key is no longer pressed
ShiftDown = false;
}
});
}
我刚刚改变了
$('input#chat').bind('keydown',function(e){}) 至
$('input#chat').keydown(function(e){})https://stackoverflow.com/questions/29178752
复制相似问题