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



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

这在所有情况下都有效,但当我将值更改为从Wordpress中的高级自定义字段中提取的值时就不行了。

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

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

<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;?>')">

我是个初学者$artist=get_field('artits_content'($艺术家是一个函数而不是一个值。

最新更新