1

我在这里找到了一个下拉列表: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');
            });

        });

When the dropdown items are selected text is being placed into the parent ul selection instead of going to the page I'd like it to. 这个简单的下拉菜单一切正常,我只需要禁用用所选文本替换链接的部分。我只希望锚标签能像任何人一样正常工作。

错误信息:

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);
4

1 回答 1

0

把这部分换成这个...

obj.opts.on('click',function(){
                var opt = $(this);
                obj.val = opt.text();
                window.location.href=opt.data('link');
            });

并为您li's的所有数据属性提供href/ 链接到它的去向...

IE...

     <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;
            });
于 2013-07-08T19:53:51.177 回答