实施时,我在控制台中收到以下验证错误amp-iframe:
<amp-iframe width="600" height="140" layout="responsive" sandbox="allow-scripts allow-same-origin allow-modals allow-popups allow-forms" resizable src="https://mydomain/page.html"></amp-iframe>
Run Code Online (Sandbox Code Playgroud)
必须为可调整大小的框架定义溢出元素
任何想法如何解决这个问题?
我正在使用 AMP 表单,无法弄清楚如何在使用一些附加元素提交表单后显示相同的 html。
一般来说,我的标记比较复杂,但这里有简单的示例来说明我需要做什么:
<form method="post" action-xhr="https://example.com/subscribe" target="_top" id="form1">
<ul>
<li>
<h2>Title 1</h2>
<input type="radio" value="1" name="answer" id="1" on="change:form1.submit">
<!-- Show this only on submit-success and there are used
some variables from amp-mustache -->
<div>Some Html {{Votes}}</div>
</li>
<li>
<h2>Title 2</h2>
<input type="radio" value="2" name="answer" id="2" on="change:form1.submit">
<!-- Show this only on submit-success and there are used
some variables from amp-mustache -->
<div>Some Html {{Votes}}</div>
</li>
...
</ul>
</form>
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用这样的东西,但不想重复标记(正如我提到的,它比提供的示例更复杂):
<form method="post" action-xhr="https://example.com/subscribe" target="_top" id="form1">
<ul>
<li>
<h2>Title 1</h2> …Run Code Online (Sandbox Code Playgroud) <style amp-custom>
{% include "style.css" %}
</style>
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个简单的 AMP 站点,但遇到了一些问题。什么是 {% %}?它对我不起作用?
我正在开发我的第一个 AMP 网站,想知道是否可以显示/隐藏多个 div:根据用户选择进行更改,就像这样。
<div class="ampstart-input" id="index">
<select name="product_type" id="product_type" required>
<option value="type_one">Type one</option>
<option value="type_two">Type two</option>
<option value="type_three">Type three</option>
<option value="type_four">Type four</option>
</select>
</div>
<div class="loan" id="type_one" hidden">Content for product one</div>
<div class="loan" id="type_two" hidden">Content for product two</div>
<div class="loan" id="type_three" hidden">Content for product three</div>
<div class="loan" id="type_four" hidden">Content for product four</div>
Run Code Online (Sandbox Code Playgroud)
当用户更改选择字段时,我希望能够显示所选产品并隐藏其他产品(并可能隐藏原始选择 #index)。这在 JavaScript 中很熟悉也很简单,但我在 AMP 中找不到任何方法来实现它。任何帮助将不胜感激。谢谢你。
我在 AMP 结合 amp-state 和 amp-position-observe 时遇到了问题。
<amp-state id="myState">
<script type="application/json">
{
"visible": "n"
}
</script>
</amp-state>
<amp-state id="variableChange">
<script type="application/json">
{
"visible": "y"
}
</script>
</amp-state>
<amp-position-observer on="enter:variableChange"
layout="nodisplay">
</amp-position-observer>
Run Code Online (Sandbox Code Playgroud)
此代码返回一个奇怪的错误:
<amp-state id="myState">
<script type="application/json">
{
"visible": "n"
}
</script>
</amp-state>
<amp-state id="variableChange">
<script type="application/json">
{
"visible": "y"
}
</script>
</amp-state>
<amp-position-observer on="enter:variableChange"
layout="nodisplay">
</amp-position-observer>
Run Code Online (Sandbox Code Playgroud) 我有一些选择,最后一个选项是“其他”。
当用户从下拉列表中选择其他选项时,我想显示文本字段。
我正在使用普通的 html,对不起,我是 AMP 初学者,我找到了一些带有 json 选项的 amp-list 示例,但我不知道如何实现,因为我在下拉列表中的选项有限。
<select data-type="text" id="cuisine" name="cuisine" required>
<option value="german">German wine</option>
<option value="baden">Baden cuisine</option>
<option value="hamburg">Hamburg cuisine</option>
<option value="others">Others</option>
<select>
<div class="form-group hide" id="other_cusone">
<label for="other_city_p" class="active">Other :</label>
<input type="text" id="other_c_p" name="other" placeholder="Other">
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢
更具体地说,您能否在未通过 AMP 验证的页面上使用 AMP 标记和代码?
用例:我想让我的网站完全使用 AMP,为此,我需要使用诸如on='tap:'下拉菜单和<amp-analytics>跟踪之类的东西,但我的网站仍有一些组件尚未准备好使用 AMP。
依靠这些 AMP 技术,我的网站能否上线,即使该网站尚未完全符合 AMP 标准?
编辑:这个问题是独一无二的,因为我打算成为 AMP 兼容,但我正在等待一些更改,然后再做,在那之前我希望我的网站上线并且不被谷歌索引为 AMP,但仍然在 Google 搜索中提供。下面的最佳答案确实解决了这个问题。
我有一个名为 currentItem 的状态,其中包含 url、标题、描述...当我按下按钮时,currentItem 应保存在名为 myItems 的其他状态中。它将包含一个项目对象列表。
现在的问题是它总是显示最后一个项目,因此它会覆盖每个 currentItem 提交的整个列表。
我的州:
<amp-state id="currentItem">
<script type="application/json">
{
"url": "",
"imageUrl": "",
"title": "",
"description": ""
}
</script>
</amp-state>
<amp-state id="myItems">
<script type="application/json">
[]
</script>
</amp-state>
Run Code Online (Sandbox Code Playgroud)
列表定义:
<amp-list class="mt3"
layout="fixed-height"
height="0"
[src]="myItems"
[height]="myItems.length * 200"
items="."
binding="no">
<template type="amp-mustache">
...
</template>
Run Code Online (Sandbox Code Playgroud)
将 currentItem 添加到列表的操作:
<button type="button"
on="tap:AMP.setState({ myItems: [currentItem]})">
Add
</button>
Run Code Online (Sandbox Code Playgroud)
我尝试使用 AMP.setState({ myItems: myItems.concat(currentItem)}) 但它崩溃了,也与 + 一起崩溃。我怎样才能做到这一点?
假设我有一个 APPLE 播客按钮和一个 GOOGLE 播客按钮,我想显示:
我目前正在通过 AMP 使用<amp-list>和调用动态生成的 JSON 文件来实现这一点。效果很好;但我想知道,如果有,将删除要求这三个文件的原生方式- <amp-list>,<amp-mustache>被加载-和动态JSON文件。
我聘请了一名开发人员来提高我的网站加载速度。他建议将 AMP 用于 Wordpress 插件。他在移动设备和桌面设备上都给了我 100 分的满分。我对此非常怀疑,因为我的网站很重,其他开发人员甚至不会承诺 90+ 的分数。我很确定这个开发人员只是在骗我 - 我想知道我如何才能找到?
有人可以帮我诊断该网站以查明它是否真实吗?听起来好得令人难以置信。