doumu1873 2018-12-10 11:15
浏览 114

在OnClick JS函数中添加高级自定义字段

I have a JS function that replaces text inside a h2 and span. The JS function is run using OnClick.

This works in all cases, but NOT when I change the value to what is pulled from an Advanced Custom Field in Wordpress.

Whenever the code is changed to the_field('content'); or get_field('content'); in a variable, it throws up the error SyntaxError: unexpected EOF.

The Field is a basic text field, that currently outputs:

<p>test8</p>  

It is being pulled in correctly in the html if I check the source.

The code:

 <script type="text/javascript">
      function ReplaceHeader(id,content) {
      var container = document.getElementById(id);
      container.innerHTML = content;
      }
</script>

    <?php $artist = get_field('artists_content'); ?>
         <a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">

      <path class="st3" d="M383.5,238.6c3.8,0,6.8-3.1,6.8-6.8s-3.1-6.8-6.8-6.8c-3.8,0-6.8,3.1-6.8,6.8l0,0
      C376.6,235.5,379.7,238.6,383.5,238.6"/>
      <text transform="matrix(1 0 0 1 398.2288 235.1945)" class="st3 st4 st5">ARTISTS</text>
    </a>

This works:

<a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<p>Test8</p>')">

and even this works:

<?php $artist = '<p>Test8</p>' ?>
    <a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">

But this doesn't:

<?php $artist = get_field('artists_content'); ?>
         <a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">
  • 写回答

1条回答 默认 最新

  • dougong2005 2018-12-10 12:15
    关注

    I am a beginner. $artist = get_field('artists_content'); $artist is a func not a value.

    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀