我正在尝试使用远程 .js 文件在 AMP 页面上实现自定义 javascript 显示/隐藏切换功能,但没有成功。
以下是常规网页上的功能代码示例:https://japan-translators.saeculii.com/english/services/japanese-translations-police-records.cfm
(点击“相关搜索”部分)
在相应的 AMP 页面上使用相同的代码:https://japan-translators.saeculii.com/english/amp/japanese-translations-police-records.cfm
标题中的代码:
<script
async custom-element="amp-script"
src="https://cdn.ampproject.org/v0/amp-script-0.1.js"
></script>
.js 文件:
function toggle_visibility(id) {
var e = document.getElementById(id);
e.style.display = ((e.style.display!='none') ? 'none' : 'block');
}
amp 脚本包装器:
<amp-script src="https://japan-translators.saeculii.com/technical/commonFiles/javascript/toggle.js">
<dd>
<a onclick="toggle_visibility('FAQ1');" class="content_link" title="For how long is a Japanese police certificate valid?"><img src="#images_href#arrow_black.gif" width="10" height="10" border="0" title="CLICK TO TOGGLE CONTENT" alt="How do I get an official translation?" /> For how long is a Japanese police certificate valid?</a><br />
<div id="FAQ1" style="display:none;">
<br /><br />
Typically, two years from the date of issue.
<br /><br />
<u>However</u>, this will depend on where and for what purpose you are submitting your certificate. Therefore, you should inquire directly at the organization that will be evaluating your documents.
<hr />
<br /><br />
</div>
</dd>
</amp-script>
任何帮助将不胜感激!预先感谢。
AMP 的设计不运行任何自定义 Javascript 代码,因此如果您想在 AMP 页面上进行一些交互,您需要使用 AMP 原生选项。请参阅 AMP 文档中的此页面,了解相关信息