6

我正在尝试通过下拉列表链接到其他 html 页面,并且我尝试了各种代码,但似乎无法使其正常工作。我正在使用这段代码:

    <form name="dropdown">
<select name="list" accesskey="target">
<option selected>Choose a theme</option>
<option value="index.html">Theme 1</option>
<option value="theme2.html">Theme 2</option>
<option value="theme3.html">Theme 3</option>
<select>
<input type=button value="Go" onclick="goToNewPage(document.dropdown.list)">

我有不同的 html 页面布局不同以在布局之间交替,我怎样才能让它工作?

4

1 回答 1

14

你可以试试这个

<form>
<select name="list" id="list" accesskey="target">
    <option value='none' selected>Choose a theme</option>
    <option value="index.html">Theme 1</option>
    <option value="theme2.html">Theme 2</option>
    <option value="theme3.html">Theme 3</option>
</select>
<input type=button value="Go" onclick="goToNewPage()" />
</form>

JS:(将此代码放入您的<head>...</head>部分)

<script type="text/javascript">
    function goToNewPage()
    {
        var url = document.getElementById('list').value;
        if(url != 'none') {
            window.location = url;
        }
    }
</script>
于 2013-11-07T18:15:25.573 回答