Html 下拉表单,当单击元素时,无需点击提交按钮即可转到链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4347080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:34:28  来源:igfitidea点击:

Dropdown Form, when click on element, go to link without hitting a submit button

htmlforms

提问by Zach Smith

I have a dropdown form, and when the user clicks on an element I want them to go to the url I have in the code without hitting a submit button. Here is the code I have so far

我有一个下拉表单,当用户单击一个元素时,我希望他们转到代码中的 url,而无需点击提交按钮。这是我到目前为止的代码

<select name="mydropdown" class="styled" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
<option value="http://www.cats.com">Select Your Compliance Center</option>
<option value="http://www.funcats.com">Fresh Milk</option>
<option value="http://cutecats.com">Old Cheese</option>
<option value="http://lolcats.com">Hot Bread</option>
</select>

but it doesn't seem to be working.

但它似乎不起作用。

Any help would be greatly appreciated.

任何帮助将不胜感激。

回答by DiAngelo

Use this:

用这个:

<select name="mydropdown" class="styled" onChange="document.location = this.value" value="GO">
        <option value="http://www.cats.com">Select Your Compliance Center</option>
        <option value="http://cutecats.com">Old Cheese</option>
        <option value="http://lolcats.com">Hot Bread</option>
</select>

回答by Yoshiyahu

More or less the same as the other answer, but this one goes through a form.

或多或少与另一个答案相同,但这个答案通过一种形式。

<form name="linkForm" method="POST" action="" id="form">
  <select name="mydropdown" class="styled" onchange="document.getElementById('form').setAttribute('action', this.value); document.linkForm.submit(); ">
    <option value="http://www.cats.com">Select Your Compliance Center</option>
    <option value="http://www.funcats.com">Fresh Milk</option>
    <option value="http://cutecats.com">Old Cheese</option>
    <option value="http://lolcats.com">Hot Bread</option>
  </select>
</form>