gpt4 book ai didi

javascript - AMP 下拉错误 : 'onchange' may not appear in tag 'select'

转载 作者:行者123 更新时间:2023-12-01 01:25:38 24 4
gpt4 key购买 nike

我在放大器页面上有一个下拉菜单,当您单击选项时,它会将您定向到一个新页面。 AMP 不允许使用 onchange 并引发以下错误:属性“onchange”可能不会出现在标记“select”中。我发现了一个类似的问题,但通过在页面或外部 js 文件上添加自定义脚本,接受的答案并不理想(并且不应该工作)。只要我能够获得 AMP 验证成功标记,我就愿意尝试不同的方法。谢谢!

<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8" />
<link rel="canonical" href="/article.html">
<link rel="amphtml" href="/article.amp.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="shortcut icon" href="amp_favicon.png">
<style amp-custom>
body {
width: auto;
margin: 0;
padding: 0;
}
</style>
<script async src="https://cdn.ampproject.org/v0.js"></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>
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);" aria-labelledby="dropdownMenu1">
<option value="">Select an Option <i class="fa fa-caret-down"></i></option>
<option value="/option1">Option 1</option>
<option value="/option2">Option 2</option>
<option value="/option3">Option 3</option>
</select>
</body>
</html>

最佳答案

在您发表评论后,我进行了更多研究,发现了这个:https://www.ampproject.org/docs/interaction_dynamic/amp-actions-and-events

看起来你可以通过使用以下方法来完成你想要的事情:

<select on="change:AMP.navigateTo(url=event.value)">
<option value="http://google.com">google.com</option>
<option value="http://yahoo.com">yahoo.com</option>
<option value="http://bing.com">bing.com</option>
</select>

显然,适本地更新值!

如果您需要更多信息,相关功能请求位于:https://github.com/ampproject/amphtml/issues/8976链接示例如下:https://github.com/ampproject/amphtml/blob/master/examples/standard-actions.amp.html

关于javascript - AMP 下拉错误 : 'onchange' may not appear in tag 'select' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53823838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com