我在这里找到了一个下拉列表:http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/
HTML:
<ul class="dropdown" tabindex="1">
<li><a href="/user/profile">profile</a></li>
<li><a href="/user/logout">log out</a></li>
</ul>
此时的js:
function DropDown(el) {
this.dd = el;
this.placeholder = this.dd.children('span');
this.opts = this.dd.find('ul.dropdown > li');
this.val = '';
this.index = -1;
this.initEvents();
}
DropDown.prototype = {
initEvents : function() {
var obj = this;
obj.dd.on('click', function(event){
$(this).toggleClass('active');
return false;
});
obj.opts.on('click',function(){
var opt = $(this);
obj.val = opt.text();
obj.index = opt.index();
obj.placeholder.text('profile: ' + obj.val);
});
},
getValue : function() {
return this.val;
},
getIndex : function() {
return this.index;
}
}
$(function() {
var dd = new DropDown( $('#dd') );
$(document).click(function() {
// all dropdowns
$('.wrapper-dropdown-1').removeClass('active');
});
});
当选择下拉项时,文本将被放入父级ul选择中,而不是转到我想要的页面。这个简单的下拉列表一切正常,我只需要禁用用所选文本替换Link的部分。我只是想让锚标签正常工作。
错误消息:
try
84 {
85 if ( ! class_exists($prefix.$controller))
86 {
87 throw new HTTP_Exception_404('The requested URL :uri was not found on this server.',
88 array(':uri' => $request->uri()));
89 }
90
91 // Load the controller using reflection
92 $class = new ReflectionClass($prefix.$controller);
答案 0 :(得分:0)
只需用此替换此部分......
obj.opts.on('click',function(){
var opt = $(this);
obj.val = opt.text();
window.location.href=opt.data('link');
});
并为li's
所有href
个数据属性提供 <li data="http://newpage.html">New Page</li>
/链接...
...即
li
除非你的<a>
元素中包含 obj.opts.on('click',function(){
var opt = $(this);
link = opt.closest('a').attr('href');
window.location.href=link;
});
个元素,否则你可能只是做这样的事情......
{{1}}