2012-06-30 2 views
-1

이 스크립트를 가지고 특정 div에 추가하고 싶습니다. 지금은 팝업창으로 경고합니다.경고 jquery 도움말, div/span 내에 들어가는 텍스트가 필요합니다.

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); 
}); 
+0

'success && success'? 이것은 새로운 종류의'if' 문입니까? – undefined

+0

@undefined :'success'는'false'로 설정 될 수 있고 JS에서는 올바르게 기억한다면 '&&' 단락 회로를 설정할 수 있습니다. 그것은 (다소 혼란 스럽다) 속기. – Blender

답변

1

자바 스크립트 :

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

HTML : 난 당신이 문서를 참조해야한다고 생각

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

편집 : @Blender가이 도움이 조각을 가지고 모든 것을 분명하게하십시오 : http://jsfiddle.net/eytkU/2/

+0

답변이 잘못되었으므로 문서를보아야한다고 생각합니다. – user1477535

+0

@ user1477535 :) – undefined

+1

아니요,이 대답은 정확합니다. 귀하의 태그가 말한 것처럼 jQuery를 사용하면 모든 브라우저에서 버그없이 작동 할 것입니다. – OptimusCrime