Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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 发生else语句时,如何添加HTML/CSS警报?_Javascript_Html_Css_Node.js_Socket.io - Fatal编程技术网

Javascript 发生else语句时,如何添加HTML/CSS警报?

Javascript 发生else语句时,如何添加HTML/CSS警报?,javascript,html,css,node.js,socket.io,Javascript,Html,Css,Node.js,Socket.io,我想将一些HTML添加到javascript中,因此当有人写入超过200个字符时,它会弹出一个无法写入超过200个字符的弹出窗口 server.js: socket.on("message", function(message, callback, req) { if(message.text.length < 200) { message.timestamp = moment().valueOf(); io.to(connectedUser

我想将一些HTML添加到javascript中,因此当有人写入超过200个字符时,它会弹出一个无法写入超过200个字符的弹出窗口

server.js:

  socket.on("message", function(message, callback, req) {
    if(message.text.length < 200) {
    message.timestamp = moment().valueOf();
    io.to(connectedUsers[socket.id].room).emit("message", message);
    } else {
      "Where the HTML/CSS will be"
    }
  });
socket.on(“消息”,函数(消息,回调,请求){
如果(message.text.length<200){
message.timestamp=moment().valueOf();
io.to(connectedUsers[socket.id].room).emit(“message”,message);
}否则{
“HTML/CSS的位置”
}
});
HTML/CSS:

<style>
.alert {
  padding: 20px;
  background-color: #f44336;
  color: white;
}

.closebtn {
  margin-left: 15px;
  color: white;
  font-weight: bold;
  float: right;
  font-size: 22px;
  line-height: 20px;
  cursor: pointer;
  transition: 0.3s;
}

.closebtn:hover {
  color: black;
}
</style>
<div class="alert">
  <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span> 
  <strong>Warning!</strong> You cannot write over 200 characters.
</div>

.警惕{
填充:20px;
背景色:#f44336;
颜色:白色;
}
.关闭{
左边距:15px;
颜色:白色;
字体大小:粗体;
浮动:对;
字体大小:22px;
线高:20px;
光标:指针;
过渡:0.3s;
}
.closebtn:悬停{
颜色:黑色;
}
&时代;
警告您不能写入超过200个字符。

因此,当有人键入超过200个字符时,此HTML/CSS将在其屏幕上弹出。

为什么需要为此与服务器通信?这是一个纯粹的前端问题,不是吗?为什么不是一个简单的弹出/警报/模式?我该怎么做?我是HTML和CSS的初学者,所以我没有任何线索。
if(input.value.length>200)alert(“你不能键入超过200个字符”)
:)我的意思是,你不知道怎么做,而且你已经在建聊天室了??也许您应该首先从基础知识开始:)您必须将其添加到客户端代码中,而不是添加到nodeJS代码中@JeremyThille所有初学者现在都从聊天室和面部识别开始,就像我们以前从扫雷舰开始一样。。O tempora,O moresAlert没有在NodeJS中定义,因为代码在服务器上运行,而不是在浏览器中运行。。。真正友好的好建议,停在原地,从最基本的东西开始,比如浏览器和服务器(前端和后端)的区别