2016-12-20 3 views
0

의 특성 'postscribe'을 설정할 수 없습니다 :가 null

Cannot set property 'postscribe' of null. 

내 코드가

입니다
$(document).on('click', '.btn', function() { 
    google_ad_client = "pub-9999999999999999"; 
    google_ad_slot = "9999999999"; 
    google_ad_width = 300; 
    google_ad_height = 250; 
    postscribe('#adv1', '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"><\\/script>'); 
}) 

사람이 도와 줄 수 ?

답변

0

이 오류는 게시 한 요소 (#adv1)가 스크립트 실행 당시 DOM에 존재하지 않는다는 것을 의미합니다.

스크립트를 실행하기 전에 먼저 #adv1을 DOM에 추가하십시오. 다음과 같이 할 수 있습니다.

$("body").append("<div id='adv1'>") 
postscribe('#adv1', '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"><\\/script>');