-1

我有这个脚本,想把它添加到一个特定的 div 中。现在它只是通过弹出窗口发出警报。

function getTime(zone, success) {
    var url = 'http://json-time.appspot.com/time.json?tz=' + zone,
        ud = 'json' + (+new Date());
    window[ud]= function(o){
        success && success(new Date(o.datetime));
    };
    document.getElementsByTagName('head')[0].appendChild((function(){
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = url + '&callback=' + ud;
        return s;
    })());
}

getTime('US\/Hawaii', function(time){
    // This is where you do whatever you want with the time:
    alert(time);
});
4

1 回答 1

1

javascript:

$("div#specific_id").append(time);

html:

<div id="specific_id">the time will be added after this text</div>

I think you should see the documentation

EDIT: @Blender have make this helping snippet, to make everything clear: http://jsfiddle.net/eytkU/2/

于 2012-06-30T23:36:53.817 回答