我希望句子和时间在同一行

时间:2018-01-06 16:26:56

标签: javascript html html5 time

有人可以帮我解决这个问题。我希望单词和时间在同一行滚动,因为我所做的那个没有连接在一起。

    <!DOCTYPE html>
<html>
<head>
    <title>Time</title>
</head>
<body>

<marquee bgcolor="blue" width"1000" height="50"> 
<script>
function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML =
    h + ":" + m + ":" + s;
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
</script><body onload="startTime()"> <div id="txt"></div> Philippine Standard Time (GMT+0800)</marquee>

</body>
</html>

3 个答案:

答案 0 :(得分:0)

 <!DOCTYPE html>
<html>
<head>
    <title>Time</title>
</head> 


<body onload="startTime()"> 
<marquee bgcolor="blue" width"1000" height="50"> 
<div>
  <span id="txt"></span>
  <span>Philippine Standard Time (GMT+0800)</span>
</div>
</marquee>

<script>
function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML =
    h + ":" + m + ":" + s;
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
</script>

</body>
</html>

答案 1 :(得分:0)

尝试为其他文字内嵌显示div添加样式#txt { display: inline-block; }

答案 2 :(得分:0)

这是代码......

<!DOCTYPE html>
<html>
<head>
    <title>Time</title>
</head>
<body>

<marquee bgcolor="blue" width"1000" height="50"> 
<script>
function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML =
    h + ":" + m + ":" + s + " Philippine Standard Time (GMT+0800)";
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;

}
</script><body onload="startTime()"> <div id="txt"></div>  </marquee>

</body>
</html>

不是使用Javascript单独加载时间,而是使用HTML加载其他字符串,您最好使用Javascript。希望它有所帮助...