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; <--- separates Local time from the digits in Chrome.
However ---> myClock.textContent = 'Local time:\\n' + h + ":" + m + ":" + s; <--- is supposed to do the same just in Firefox but it doesn't work.
I have tried with \\n\\r, \\r\\n, /\\n/ and /\\r/ Nothing worked for me..
Use <br>
as line break. HTML collapses whitespace:
myClock.innerHTML = 'Local time:<br>' + h + ":" + m + ":" + s;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.