如何获得下拉值变化的下拉数据?

时间:2018-02-28 10:34:45

标签: javascript jquery amp-html

您能否告诉我如何获取下拉值变化的下拉数据? 我正在使用此链接进行链接下拉列表

https://ampbyexample.com/advanced/linked_dropdowns/ 这是我的代码

当我选择第一个选项(ZILA SAHAKRI BANK LIMITED GHAZIABAD)。我希望从此网址的第二个下拉列表中加载数据

网址中有数据

这是我的代码

<!doctype html>
<html ⚡>
<head>
    <title>Linked Dropdowns</title>
    <link rel="canonical" href="https://ampbyexample.com/advanced/linked_dropdowns/">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <!-- #### Setup -->
    <!-- First we include `amp-bind` to track the page state and update the ``<amp-list>` data source. -->
    <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
    <!-- Next we include `amp-list` to request and display the dropdowns and their options. -->
    <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
    <!-- Finally, we include `amp-mustache` to render the mustache templates inside the `<amp-list>`s. -->
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.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>

    <style amp-custom>
        label {
            font-weight: bold;
        }

        [role="listitem"] {
            display: flex;
        }

        [role="listitem"] > * {
            flex: 1 0 0;
        }

        amp-list {
            margin: 10px 20px;
            min-width: 240px;
        }

    </style>
</head>
<body>

<div>
    <amp-list width="auto" single-item items="." height="25" layout="fixed-height"
              src="https://biz.com/getlist">
        <template type="amp-mustache">
            <label for="country">Country:</label>
            <select id="country"
                    on="
                  change:
                    AMP.setState({
                      cities: dropdown.data.filter(x => x.text_val == event.value)[0]
                    })">
                 <option value="">Choose country</option>

                {{#data}}
                <option value="{{text_val}}">{{text_val}}</option>
                {{/data}}
            </select>
        </template>
    </amp-list>


    <amp-list width="auto"
              height="25"
              layout="fixed-height"
              single-item items="."
              [src]="cities || 'https://biz.com/bankifddsc/getlist?seo_bank='+cities.seo_val"
              src="https://biz.com/bankifddsc/getlist?seo_bank='+cities.seo_val">
        <template type="amp-mustache">
            <label for="city">City:</label>
            <select [disabled]="!cities"
                    disabled
                    id="city">
                {{#data}}
                <option value="{{seo_val}}">{{text_val}}</option>
                {{/data}}
            </select>
        </template>
    </amp-list>


</div>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

试试这个:

<!doctype html>
<html ⚡>
<head>
    <title>Linked Dropdowns</title>
    <link rel="canonical" href="https://ampbyexample.com/advanced/linked_dropdowns/">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <!-- #### Setup -->
    <!-- First we include `amp-bind` to track the page state and update the ``<amp-list>` data source. -->
    <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
    <!-- Next we include `amp-list` to request and display the dropdowns and their options. -->
    <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
    <!-- Finally, we include `amp-mustache` to render the mustache templates inside the `<amp-list>`s. -->
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.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>

    <style amp-custom>
        label {
            font-weight: bold;
        }

        [role="listitem"] {
            display: flex;
        }

        [role="listitem"] > * {
            flex: 1 0 0;
        }

        amp-list {
            margin: 10px 20px;
            min-width: 240px;
        }

    </style>
</head>
<body>

<div>
    <amp-list width="auto" single-item items="." height="25" layout="fixed-height"
              src="https://example.com/getlist">
        <template type="amp-mustache">
            <label for="country">Country:</label>
            <select id="country"
                    on="change:AMP.setState({cities: event.value})">
                 <option value="">Choose country</option>

                {{#data}}
                <option value="{{seo_val}}">{{text_val}}</option>
                {{/data}}
            </select>
        </template>
    </amp-list>
    <amp-list width="auto"
              height="25"
              layout="fixed-height"
              single-item items="."
              [src]="'https://example.com/getlist?seo_bank='+cities"
              src="https://example.com/getlist?seo_bank=1">
        <template type="amp-mustache">
            <label for="city">City:</label>
            <select [disabled]="!cities"
                    disabled
                    id="city">
                {{#data}}
                <option value="{{seo_val}}">{{text_val}}</option>
                {{/data}}
            </select>
        </template>
    </amp-list>

   </div>

</body>
</html>

使用您的域名更改example.com