简体   繁体   中英

open a dropdown-menu toggle on hover - knockout

I am trying to add and close the dropdown on hover using knockout and jquery .

FIDDLE HERE

Here is the simple HTML

<div class="btn-group">
    <button type="button" class="btn btn-default dropdown-toggle"
            data-toggle="dropdown" data-bind="event: { mouseover: enableDetails, mouseout: disableDetails }">
        Lists
    </button>

    <ul class="dropdown-menu" role="menu">
        <li>
            <a href="#">Sub List 1</a>
        </li>
        <li>
            <a href="#">Sub List 2</a>
        </li>
    </ul>
</div>

Ideally $(".dropdown-toggle").dropdown(); should work when placed within the enableDetails method in your fiddle. But this $(".dropdown-toggle").dropdown('toggle'); seems to work. Here is the updated fiddle. The dropdown function is from the bootstrap documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM