Jquery下拉列表链接

时间:2016-01-06 17:30:05

标签: jquery drop-down-menu

这是我的程序中的示例下拉列表。 目前链接仅适用于此列表,如何在此列表旁边创建另一个下拉列表?我如何解决getElementById("list").value

感谢您的帮助。

<select name="list" Id="list" accesskey="target">
    <option value='none' selected>Choose a Destination</option>
    <option value="europeresort.html">Europe</option>
    <option value="africaresort.html">Africa</option>
    <option value="northamericaresort.html">North America</option>
    <option value="southamericaresort.html">South America</option>
    <option value="thealpsresort.html">The Alps</option>
    <option value="carribeanresort.html">Carribean</option>
    <option value="indianoceanresort.html">Indian Ocean</option>
    <option value="asiaresort.html">Asia</option>
<select>
<input type=button value="Go" onclick="goToNewPage()" />

1 个答案:

答案 0 :(得分:0)

问题是你的两个下拉列表的id是一样的。这就是为什么你总是得到第一次下拉的价值。以下代码段可能会对您有所帮助。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select name="list" id="list" accesskey="target">
    <option value='none' selected>Choose a Destination</option>
    <option value="europeresort.html">Europe</option>
    <option value="africaresort.html">Africa</option>
    <option value="northamericaresort.html">North America</option>
    <option value="southamericaresort.html">South America</option>
    <option value="thealpsresort.html">The Alps</option>
    <option value="carribeanresort.html">Carribean</option>
    <option value="indianoceanresort.html">Indian Ocean</option>
    <option value="asiaresort.html">Asia</option>
</select>
<input type="button" value="Go"/>

<select name="list" id="list" accesskey="target">
    <option value='none' selected>Choose a Comfort Level</option>
    <option value="comfort3star.html">Comfort 3 star</option>
    <option value="theme2.html">Premium 4 star</option>
    <option value="theme3.html">Luxury 5 star</option>
</select>
 <input type="button" value="Go"/>

<script>
    $('input').click(function() {
        var url = $(this).prev('select').val();
        if (url != 'none')
            window.location = url;
    });
</script>