如何重定向页面放大器?

编程入门 行业动态 更新时间:2024-10-10 10:28:17
本文介绍了如何重定向页面放大器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将以下javascript代码调整为适用于amp页面.

I need to adapt the following javascript code to an amp page.

<select id="url"> <option value='home'>home</option> <option value='contact'>contact</option> </select> <input type="button" value='ir' onclick='ir()'> <script> function ir(){ var url=document.getElementById("url").value; location.href=url; } </script>

有可能吗?

在文档中我找不到答案.

In the documentation I did not find the answer.

推荐答案

您正在使用按钮和onclick函数,在AMP中,您可以使用锚标记<a href="Value">Value</a>并使用`amp-bind'

You are using button and onclick function, in place of this in AMP you can use anchor tag <a href="Value">Value</a> and change the url using `amp-bind'

您可以使用amp-bind实现目标

> 这是有效的URL

在标头中添加JS

<script async custom-element="amp-bind" src="cdn.ampproject/v0/amp-bind-0.1.js"></script>

在正文中添加代码

<div class="wrapper"> <select on="change:AMP.setState({ url: event.value })"> <option value='home'>home</option> <option value='contact'>contact</option> </select> <a [href]="url" href="home">ir</a> </div>

已更新-如果某人想更改选项时重定向而不是使用navigateTo操作

Updated - if some one want to redirect on option change than use navigateTo action

示例:

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

更多推荐

如何重定向页面放大器?

本文发布于:2023-11-28 18:57:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放大器   重定向   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!