2016-12-20 66 views
0

的特性 'postscribe' 當我打電話 「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

此錯誤表示您在腳本運行時向DOM提供的元素(#adv1)不存在。

在運行腳本之前,首先將#adv1添加到DOM。你可以這樣做:

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