css - 如何将工作时钟转换为文本?

标签 css html

我正在尝试将实时时钟放入文本正文中。我需要它像文本的一部分一样流动,但仍然对本地设备有效。在 Adob​​e Muse 中玩转我已经能够在文本中找到时钟,但它把自己隔离在自己的行中,而不是像段落的一部分那样流动。

以下是 Muse 生成的代码。我假设我需要对 actAsInlineDiv normal_textactAsDiv excludeFromNormalFlow 或两者进行更改,但如何更改?

 <p id="u3202-10"><span class="Character-Style">You look at the clock on this device and it reads </span><span class="Character-Style"><span class="actAsInlineDiv normal_text" id="u13390"><!-- content --><span class="actAsDiv excludeFromNormalFlow" id="u13388"><!-- custom html --><html>
<head>
<script type="text/javascript">
    function startTime()
    {
        var today=new Date();
        var h=today.getHours();
        var m=today.getMinutes();
    // add a zero in front of numbers<10
    m=checkTime(m);

    document.getElementById('txt').innerHTML=h+":"+m;
    t=setTimeout('startTime()',500);
}
function checkTime(i)
{
    if (i<10)
    {
        i="0" + i;
    }
    return i;
}
</script>
</head>
<body onload="startTime()">
    <div id="txt"></div>
</body>
</html>
    </span></span></span><span class="Character-Style">As a result you believe that this is the time. As it happens this is the time but unknown to you your device's clock has stopped functioning and is stuck. Does your true belief that this is the time count as knowledge?</span></p>

最佳答案

我不知道 Muse,但如果你想要的只是一个当前时间的时钟与一些文本内联运行,你可以这样做:

window.onload = displayTime;
function displayTime() {
    var element = document.getElementById("clock");
    var now = new Date();
    var options = {hour: '2-digit', minute:'2-digit'};
    element.innerHTML = now.toLocaleTimeString(navigator.language, options);
    setTimeout(displayTime, 1000);
}
The current time is <span id="clock"></span> and it's inline with text.

编辑

我添加了这两行以按照您在评论中的要求从显示中删除秒数。

var options = {hour: '2-digit', minute:'2-digit'};
element.innerHTML = now.toLocaleTimeString(navigator.language, options);

关于css - 如何将工作时钟转换为文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29453796/

相关文章:

jquery - 使按钮宽度 100%,MVC 5 Bootstrap 3

javascript - CSS 和 Javascript 可在内部服务器上运行,但不能在外部服务器上运行

html - CSS 1px 边框描边围绕边框半径断开

javascript - 如何在 Electron js中创建模态? (javascript,html,css)

css - div 上的“border-bottom”出现在顶部? Div 没有环绕文字?

html - css 位置不适用于粘性

javascript - 使用javascript css隐藏显示div

html - Bootstrap 模式登录

jquery - 如何在 jquery 中删除一行后重置表行号?

android - 使用 HTML5 标签播放视频