Html 选择框内的链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5382730/
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
Link Inside Select Box
提问by Chris Muench
Is it possible to display an html link inside a multi select box that can be navigated to?
是否可以在可以导航到的多选框中显示 html 链接?
采纳答案by zzzzBov
Yes and no.
是和否。
You cannot make a link inside a select
element, however you canmake a select element that will change the page when an option is selected. (Probably not what you want)
您不能在select
元素内部创建链接,但是您可以创建一个选择元素,该元素将在选择选项时更改页面。(可能不是你想要的)
Additionally, you can make your own pseudo-select box using a combination of input:radio
elements, CSS, and JavaScript. This pseudo-select box can be customized to contain anchor elements and other such things if needed.
此外,您可以使用input:radio
元素、CSS 和 JavaScript的组合来制作自己的伪选择框。如果需要,可以自定义此伪选择框以包含锚元素和其他此类内容。
回答by Bala R
You could use the value attribute to store the url
您可以使用 value 属性来存储 url
<select >
<option value="www.yahoo.com">yahoo</option>
...
</select>
have use javascript to retrieve the value when an item is selected and redirect to that URL.
在选择项目并重定向到该URL时,已使用JavaScript来检索值。
回答by ace
You can try to add an onClick event into the option button that will behave like an anchor tag.
您可以尝试将 onClick 事件添加到选项按钮中,该事件的行为类似于锚标记。
<select multiple>
<option onClick="window.location = 'http://www.google.com'" >google</option>
<option onClick="window.location = 'http://www.stackoverflow.com'">stackoverflow</option>
</select>