【问题标题】:Amp dropdown with other option带有其他选项的放大器下拉菜单
【发布时间】:2018-06-16 07:39:02
【问题描述】:

我有一些选择,其中最后一个选项是“其他”。

当用户从下拉列表中选择其他选项时,我想显示文本字段。

我使用的是普通的 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>

谢谢

【问题讨论】:

    标签: amp-html amp-bind amp-list


    【解决方案1】:

    对于有限的选项,您不必使用 amp-list,它用于动态下拉菜单。您可以使用 amp-bind 来实现您的目标。

    Here is working url

    代码:

    <!doctype html>
    <html ⚡>
    <head>
      <meta charset="utf-8">
      <title> AMP amp-bind </title>
      <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>
      <link rel="canonical" href="https://ampbyexample.com/introduction/hello_world/">
      <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
      <style amp-custom>
    
      </style>
      <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 on="change:AMP.setState({ option: event.value })" 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  hidden [hidden]="option != 'others'" 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>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多