我有很多关于例如link1,link2,link3,link4 ... link9的链接。 我必须在下拉列表中添加这些链接。我尝试使用rails select_tag和html标签
使用html select标记
<span class="device_update">
<select>
<option value="link1"><%= link_to "link1", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option>
<option value="link2"><%= link_to "link2", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option>
<option value="link3"><%= link_to "link3", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option>
......
<option value="link9"><%= link_to "link9", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option>
</select>
</span>
如何制作多个链接的下拉列表
答案 0 :(得分:5)
我是通过以下方式做到的。为此,我请参考bootstrap button dropdowns
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><%= link_to "link1", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></li>
<li><%= link_to "link1", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></li>
<li><%= link_to "link3", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></li>
<li class="divider"></li>
<li><%= link_to "link4", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></li>
</ul>
</div>
答案 1 :(得分:1)
正如 @anonymousxxx 所说,link_to
内不能有hyperlink
或optiontag
。
您最好使用jquery slideToggle()
列出drop-down
链接
<div class="button">click me</div>
<div class="dropdown">
<a href="">link1</a>
<a href="">link2</a>
<a href="">link3</a>
<a href="">link4</a>
</div>
Jquery代码是
$(".button").click(function(){
$(".dropdown").slideToggle();
});
<强> Working Demo 强>