我的作业有问题。在我解释这个之前,我想对我的英语表示歉意。 因此,我尝试在node.js中进行聊天。我从网站“ https://openclassrooms.com/fr/courses/1056721-des-applications-ultra-rapides-avec-node-js/1057959-tp-le-super-chat”中选择了一个小代码。 它运作良好。聊天使用输入文本来发送消息。
我的问题是:本次聊天使用的是jQuery库,而且它太老了,我想将jQuery的功能转换为本地javascript。我已经成功翻译了其中的3篇。一个人仍然抗拒。
$('#formulaire_chat').submit(function () {
var message = $('#message').val();
socket.emit('message',message); // Send the message to others clients
insereMessage(pseudo,message); // Also post the message on our page
$('#message').val('').focus(); // Empty the Chat area and put the focus back on
return false; // Allows you to block the "classic" sending of the form
});
我尝试将其变成这样:
document.getElementById('formulaire_chat').submit(function () {
var message = document.getElementById('message').value;
socket.emit('message',message); // Also post the message on our page
document.getElementById('message').value = ' ';
document.getElementById('message').focus();
return false; // Allows you to block the "classic" sending of the form
});
当我使用“翻译”功能时,出现错误“无法发布/” 我试图一遍一遍地操纵所有的线,以找出阻塞的地方。 但是,尽管我花了很多时间,但仍无法正常工作。 我正在学习代码,并且是一个初学者,所以请不要对我进行评判。