Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 时区JS,需要格式方面的帮助吗_Javascript - Fatal编程技术网

Javascript 时区JS,需要格式方面的帮助吗

Javascript 时区JS,需要格式方面的帮助吗,javascript,Javascript,此代码垂直显示时区。我希望以适当的间距水平显示它们。我想用一个标记替换“br”break标记(代码倒数第二行),该标记将在新名称和区域之间提供间距。不起作用。由于某种原因,这很简单但很棘手 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv=

此代码垂直显示时区。我希望以适当的间距水平显示它们。我想用一个标记替换“br”break标记(代码倒数第二行),该标记将在新名称和区域之间提供间距。不起作用。由于某种原因,这很简单但很棘手

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/JavaScript">
//Universal clock 2006
//Genuine code by Corneliu Lucian "KOR" Rusu mailto:corneliulucian(AROND)apropo.ro
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var D=[
['Bucharest',120,60],//city,standard time zone(minutes), DST(minutes)
['Madrid',60,60],
['New York',-300,60],
['Nairobi',180,0]
]
//add in the array your cities,STZ, DST
function calc(){
var spans=document.getElementById('zonediv').getElementsByTagName('span')
for(var i=0;i<D.length;i++){
var t=new Date();
t.setTime(t.getTime()+(t.getTimezoneOffset()*60000)+((D[i][1]+D[i][2])*60000));//the zone's time
var Dy=t.getFullYear();
var Dd=t.getDate()<10?'0'+t.getDate():t.getDate();
var Dm=t.getMonth()<10?'0'+(t.getMonth()+1):t.getMonth()+1;
var Dh=t.getHours()<10?'0'+t.getHours():t.getHours(); 
var Di=t.getMinutes()<10?'0'+t.getMinutes():t.getMinutes();
var Ds=t.getSeconds()<10?'0'+t.getSeconds():t.getSeconds();
var Dz=wd[t.getDay()];
spans[i].firstChild.data=Dh+':'+Di+':'+Ds+' - '+Dz+' '+Dd+'/'+Dm+'/'+Dy;
}
setTimeout('calc()',1000)
}
onload=function(){
var root = document.getElementById('zonediv');
for(var i=0;i<D.length;i++){
root.appendChild(document.createTextNode(D[i][0]+' '))
var sp= document.createElement('span');
sp.appendChild(document.createTextNode(' '));
root.appendChild(sp);root.appendChild(document.createElement('br'))
}
calc();
}
</script>
</head>
<body>
<div id="zonediv">
</div>
</body>
</html>

无标题文件
//世界时钟2006
//Corneliu Lucian“KOR”Rusu mailto的真实代码:corneliulucian(AROND)apropo.ro
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
变量D=[
[布加勒斯特,120,60],//城市,标准时区(分钟),DST(分钟)
['Madrid',60,60],
[‘纽约’,-300,60],
[‘内罗毕’,180,0]
]
//在阵列中添加您的城市、STZ、DST
函数计算(){
var span=document.getElementById('zonediv').getElementsByTagName('span'))
对于(var i=0;i尝试替换

root.appendChild(document.createElement('br'))

有点像

root.appendChild(document.createTextNode(“”))


这将附加一个空格,而不是
br
元素:)

完美!谢谢。我还添加了一个条,效果很好。root.appendChild(document.createTextNode(“|”);