【问题标题】:jquery code is not working in wordpress pluginjquery 代码在 wordpress 插件中不起作用
【发布时间】:2014-06-30 14:10:13
【问题描述】:

此代码工作正常并加载广告

<script type="text/javascript">google_ad_client = 'ca-pub-1702577941194110';</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>     

jquery 不起作用,它在 wordpress 插件代码下。

jQuery('#addSpace').html("") 
.append("<script type='text/javascript'>"+" google_ad_client ='"+this.title+"'"+ " </" + "script>"+"<script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>"+"</" + "script>");

有人可以帮忙吗?

【问题讨论】:

  • 等等?你有没有加载jQuery(通过脚本标签)。错误控制台说什么? (chrome 中的 f12,然后是控制台选项卡并检查错误)
  • 不是 jQuery() 已弃用还是 $() 只是简写形式?

标签: php jquery wordpress


【解决方案1】:

某些浏览器不会以这种方式更新对 HTML 的更改。最好使用内置的 fns。

试试,

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
$('#addSpace').append( script );

发件人:http://mg.to/2006/01/25/json-for-jquery

【讨论】:

  • function onAfter() { jQuery('#output').html("") .append('

    ' + this.id + '

    '+ this.alt +'

    '); var google_ad_client = this.title; google_ad_client = "google_ad_client = '"+google_ad_client+"';"; $('#addSpace').html("
【解决方案2】:

看起来 google_ad_client 在第一个脚本中应该只是一个变量,所以你应该先分配它

var google_ad_client = $('#addSpace').attr('title');

然后创建第二个脚本以附加到元素

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
$('#addSpace').html(script);

【讨论】:

  • function onAfter() { jQuery('#output').html("") .append('

    ' + this.id + '

    '+ this.alt +'

    '); var google_ad_client = this.title; google_ad_client = "google_ad_client = '"+google_ad_client+"';"; $('#addSpace').html("
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多