放大器事件后选择选项元素 [英] Select option element after event on amp
本文介绍了放大器事件后选择选项元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想自动选择第二个&的选项之一.用户更改第一个下拉菜单后,第三个下拉列表就会自动出现.
I want to automatically select one of the options of the second & third dropdowns automatically once the user changes the first one.
<body>
<h1>Hello AMPHTML World!</h1>
<label for="color">Color</label>
<select name="color" id="color" on="change:size.focus">
<option disabled selected></option>
<option value="blue">blue</option>
<option value="red">red</option>
<option value="green">green</option>
</select>
<label for="size">Size</label>
<select name="size" id="size">
<option disabled selected></option>
<option value="small">small</option>
<option value="medium">medium</option>
<option value="big">big</option>
</select>
<label for="material">Material</label>
<select name="material" id="material">
<option disabled selected></option>
<option value="paper">paper</option>
<option value="plastic">plastic</option>
<option value="wood">wood</option>
</select>
</body>
到目前为止,我只找到动作focus
,但是拥有类似select(value=small)
的东西会很棒.有什么想法或解决方法吗?谢谢!
So far, I only found the action focus
but it would be great to have something like select(value=small)
. Any idea or workaround? Thanks!
推荐答案
没有用于选择选项值的操作和事件,您可以为此使用amp-bind
There is no action and event for select the option value, You can use amp-bind
for that
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<link rel="canonical" href="amp-bind.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
</head>
<body>
<label for="color">Color</label>
<select name="color" id="color" on="change:AMP.setState({ optionValue: true })">
<option disabled selected></option>
<option value="blue">blue</option>
<option value="red">red</option>
<option value="green">green</option>
</select>
<label for="size">Size</label>
<select name="size" id="size">
<option disabled selected></option>
<option [selected]="optionValue" value="small">small</option>
<option value="medium">medium</option>
<option value="big">big</option>
</select>
<label for="material">Material</label>
<select name="material" id="material">
<option disabled selected></option>
<option [selected]="optionValue" value="paper">paper</option>
<option value="plastic">plastic</option>
<option value="wood">wood</option>
</select>
</body>
</html>
另一种通过使用不带amp-bind
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<link rel="canonical" href="amp-bind.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
</head>
<body>
<label for="color">Color</label>
<select name="color" id="color" on="change:fsize.hide,size.show,fmaterial.hide,material.show">
<option disabled selected></option>
<option value="blue">blue</option>
<option value="red">red</option>
<option value="green">green</option>
</select>
<label for="size">Size</label>
<select id="fsize">
<option disabled selected></option>
</select>
<select hidden name="size" id="size">
<option value="small">small</option>
<option value="medium">medium</option>
<option value="big">big</option>
</select>
<label for="material">Material</label>
<select id="fmaterial">
<option disabled selected></option>
</select>
<select hidden name="material" id="material">
<option value="paper">paper</option>
<option value="plastic">plastic</option>
<option value="wood">wood</option>
</select>
</body>
</html>
这篇关于放大器事件后选择选项元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文