首页 > 解决方案 > 如何在自定义 amp 脚本中使用 jquery?

问题描述

我尝试在下面的示例 AMP 页面中包含 jQuery

<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
<amp-script data-ampdevmode src="http://localhost/wptest/wp-content/themes/twentytwentyone/hello-world.js" width="300" height="100">
  <p>A single line of text</p>
  <button class="abc">text</button>
</amp-script> 

并在 hello-world.js 中运行这个简单的 jQuery 脚本:

$('button').click(function() {
    alert("hello");
    $('body').append('hello world');
})

标签: javascriptjquerywordpressamp-html

解决方案


推荐阅读