简体   繁体   English

用于Mozilla Firefox的Javascript换行符

[英]Newline in Javascript for Mozilla Firefox

Example which is not working: 示例不起作用:

<div id="clockDisplay"></div>
<script type="text/javascript" language="javascript">
function renderTime() {
    var currentTime = new Date();
    var h = currentTime.getHours();
    var m = currentTime.getMinutes();
    var s = currentTime.getSeconds();
    setTimeout('renderTime()',1000);
    if (h < 10) {
        h = "0" + h;
    }
    if (m < 10) {
        m = "0" + m;
    }
    if (s < 10) {
        s = "0" + s;
    }
    var myClock = document.getElementById('clockDisplay');
    myClock.textContent = 'Local time:\n' + h + ":" + m + ":" + s;
    myClock.innerText = 'Local time:\n'+ h + ":" + m + ":" + s;
}
renderTime();
</script>..

The ---> myClock.innerText = 'Local time:\\n'+ h + ":" + m + ":" + s; ---> myClock.innerText ='本地时间:\\ n'+ h +“:”+ m +“:”+ s; <--- separates Local time from the digits in Chrome. <---将本地时间与Chrome中的数字分开。

However ---> myClock.textContent = 'Local time:\\n' + h + ":" + m + ":" + s; 但是---> myClock.textContent ='当地时间:\\ n'+ h +“:”+ m +“:”+ s; <--- is supposed to do the same just in Firefox but it doesn't work. <---应该只在Firefox中做同样的事情,但它不起作用。

I have tried with \\n\\r, \\r\\n, /\\n/ and /\\r/ Nothing worked for me.. 我试过\\ n \\ r,\\ r \\ n,/ \\ n /和/ \\ r /没有什么对我有用..

Use <br> as line break. 使用<br>作为换行符。 HTML collapses whitespace: HTML折叠空白:

myClock.innerHTML = 'Local time:<br>' + h + ":" + m + ":" + s;

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

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