如何在AMP上实现Jquery? [英] How to implement Jquery on AMP?

查看:84
本文介绍了如何在AMP上实现Jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在AMP页面上使用JQuery.

I tried to using JQuery on AMP pages.

例如,我已经满足了对脚本/HTML amp等放大器的要求.

For example, I already fulfill the amp requirement like script/HTML amp, etc.

这里有个例子:

const button = document.getElementById('hello-url');

button.addEventListener('click', () => {
    console.log('clicked');
  const h1 = document.createElement('h1');
  h1.textContent = 'Hello World!';
  document.body.appendChild(h1);
});

<!DOCTYPE html>
<html amp lang="en">
  <head>
    <meta charset="utf-8">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <title>Hello, AMPs</title>
    <link rel="canonical" href="https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup/">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
    <meta name="amp-script-src" content="sha384-ZvpUoO_-PpLXR1lu4jmpXWu80pZlYUAfxl5NsBMWOEPSjUn_6Z_hRTt8-pR6L4N2">
    <script type="application/ld+json">
      {
        "@context": "http://schema.org",
        "@type": "NewsArticle",
        "headline": "Open-source framework for publishing content",
        "datePublished": "2015-10-07T12:02:41Z",
        "image": [
          "logo.png"
        ]
      }
    </script>
    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  </head>
  <body>
    <amp-script src="js" layout="container">
        <div id="hello-url">
            Say Hello
        </div>
    </amp-script>
  </body>
</html>

它适用于普通js,但是在Jquery上实现如何实现?

It works for vanilla js, but how about implementation on Jquery, how to do it?

<amp-script src="https://code.jquery.com/jquery-3.5.1.min.js" layout="container">
    <div id="hello-url">
        Say Hello
    </div>
<script>
  $jquerycode with same fuction
</script>
</amp-script>

推荐答案

像jQuery这样的外部Java脚本禁止.除了 AMP-Iframe

External Java Script like jQuery are forbidden in AMP. Except for AMP-Iframe or custom Javascript.

这篇关于如何在AMP上实现Jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆