0

我有一个 JS 函数,可以替换 h2 和 span 中的文本。JS 函数使用 OnClick 运行。

这适用于所有情况,但不是当我将值更改为从 Wordpress 中的高级自定义字段中提取的值时。

每当代码更改为变量the_field('content');get_field('content');变量时,它都会抛出错误 SyntaxError: unexpected EOF

Field 是一个基本的文本字段,当前输出:

<p>test8</p>  

如果我检查源代码,它将被正确地拉入 html 中。

编码:

 <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>

这有效:

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

甚至这也有效:

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

但这不会:

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

1 回答 1

0

我是初学者。$artist = get_field('artists_content'); $artist 是一个函数而不是一个值。

于 2018-12-10T12:15:32.430 回答