我有一个JS函数替换h2和span中的文本 . JS函数使用OnClick运行 .
这适用于所有情况,但不是在我将值更改为从Wordpress中的高级自定义字段中提取的值时 .
每当代码在变量中更改为 the_field('content');
或 get_field('content');
时,它都会抛出 error 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;?>')">
1 回答
我是初学者 . $ artist = get_field('artists_content'); $ artist是一个功能而非 Value .