简体   繁体   English

我在 javascript html 中断行有问题

[英]I have an issue with breaking lines in javascript html

I have an issue with breaking line in javascript.我在 javascript 中断行有问题。 It doen't make a break line in html page, how can i fix this?它不会在 html 页面中创建断行,我该如何解决这个问题?

不会刹车

 let currentDate; var botHp; var playerHp; const postlog = function(message) { document.querySelector(".gamelogchat").textContent += message; }; document.querySelector(".cardbutton").addEventListener("click", function() { console.log("click"); currentDate = new Date(); let Time = currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds(); postlog(Time + "\\r\\n"); });
 <div class="gamelog"> <h1 class="gamename">Game</h1> <p class="gamelogname">Game log</p> <div class="gamelogbox"> <p class="gamelogchat"></p> </div> </div>

Try to change on尝试改变

 document.querySelector(".gamelogchat").innerHTML += message + "<br />";

Mb, it's better to understand with demo: https://codesandbox.io/s/trusting-phoebe-9zl3h?file=/src/index.js Mb,最好用demo来理解: https : //codesandbox.io/s/trusting-phoebe-9zl3h?file=/ src/ index.js

Just use this:只需使用这个:

let currentDate;  
var botHp;  
var playerHp;  

const postlog=function(message)
{
  document.querySelector('.gamelogchat').textContent+=message;
};

document.querySelector('.cardbutton').addEventListener('click',function()
{
  console.log('click');
  currentDate=new Date();
  let Time=currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds();    
  postlog(Time+'<br/>');
});

This should fix the problem:这应该可以解决问题:

 let currentDate; var botHp; var playerHp; const postlog = function(message) { document.querySelector(".gamelogchat").innerHTML += message; }; document.querySelector(".cardbutton").addEventListener("click", function() { console.log("click"); currentDate = new Date(); let Time = currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds(); postlog(Time + "<br>");//\\r\\n });
 <div class="gamelog"> <h1 class="gamename">Game</h1> <p class="gamelogname">Game log</p> <button class="cardbutton">Test Button</button> <div class="gamelogbox"> <p class="gamelogchat"></p> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM