Semantic Ui Menu not working

妖精的绣舞 提交于 2019-12-22 09:00:11

问题


I am trying to work with semantic ui menu.

But I cannot get it to work, ie when I click the items in the menu, the active state isn't changing. I didn't find any examples in the web either.

HTML :

<div class="ui grid">
        <div class="one wide row">
            <div class="ui green menu">
                <a class="active item">
                    <i class="home icon"></i> Home
                </a>
                <a class="item">
                    <i class="mail icon"></i> Messages
                </a>
                <div class="right menu">
                    <div class="item">
                        <div class="ui transparent icon input">
                            <input type="text" placeholder="Search...">
                            <i class="search link icon"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

JS:

$(document).ready(function() {
    $('.ui .green .menu').menu();
});

I have taken the code snippet from the semantic-ui website.

Some help is appreciated.


回答1:


here's a handler similar to the one on their demo site

DEMO

screenshot:

  $('.ui.green.menu')
    .on('click', '.item', function() {
      if(!$(this).hasClass('dropdown')) {
        $(this)
          .addClass('active')
          .siblings('.item')
            .removeClass('active');
      }
    });



回答2:


Try:

$(document).ready(function() {
    $('.ui.green.menu').menu();
});

Classes ui, green and menu are applied on the same element. They're not descendants of one another.




回答3:


To make your menu LIVE with jQuery use this.

From the Semantic UI example

$('.ui.menu .ui.dropdown').dropdown({
  on: 'hover'
});
$('.ui.menu a.item').on('click', function() {   
  $(this)
    .addClass('active')
    .siblings()
    .removeClass('active'); 
})


来源:https://stackoverflow.com/questions/27500376/semantic-ui-menu-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!