我在使用 Google AdSense 时遇到了问题,它会在我的 jQuery 加载前加载并破坏我的代码,因此我想尝试使用文档准备函数将 Google AdSense JavaScript 添加到适当的 div 中,以下是我正在尝试编写的代码:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$(".googleBanners").html("<script language='javascript' type='text/javascript'>\n" + "google_ad_client = 'pub-8487967187298044';\n" + "google_ad_slot = '1088799521';\n" + "google_ad_width = 250;\n" + "google_ad_height = 250;\n" + "</" + "script>\n" + "<script language='javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript'>" + "</" + "script>");
});
</script>
但我不太擅长编写JavaScript/jQuery,所以如果有人可以帮我实现这个功能,那就太好了。
我现在在Firefox中得到的错误是“错误:google_protectAndRun未定义”。我不确定这意味着什么,但我猜测我可能错误地编写了jQuery代码..哈哈