通过下拉菜单链接到HTML中的其他页面 [英] Linking to other pages in HTML via drop-down menu

查看:214
本文介绍了通过下拉菜单链接到HTML中的其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to link to other html pages via dropdown, and I've tried various codes but can't seem to get it to work. I'm using this code:

    <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页面,它们的布局不同,可以在布局之间交替显示,如何使它起作用?

I have different html pages laid out differently to alternate between layouts, how can I get this to work?

推荐答案

您可以尝试

<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> 部分)

JS: (Put this code into your <head>...</head> secion)

<script type="text/javascript">
    function goToNewPage()
    {
        var url = document.getElementById('list').value;
        if(url != 'none') {
            window.location = url;
        }
    }
</script>

这篇关于通过下拉菜单链接到HTML中的其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆