单击下拉切换时调用函数

Calling a function when dropdown toggle is clicked

我有这个下拉开关,我想在每次单击或切换时调用函数 read();onclick 命令有问题,它总是调用函数 read();,即使未单击切换也是如此。我还尝试了其他命令,例如 ondrop

Html:

        <a data-toggle="dropdown" class="dropdown-toggle" onclick="read();">
            <i class="fa fa-globe"></i>
            <span class="badge">
                <%=unread%>
            </span>
        </a>

Javascript:

    function read() {
        <%
            notificationDAO.read(((User)session.getAttribute("user")).getEmployeeID());
        %>
    }

猜测您正在使用 bootstrap 数据切换有其自己的事件

$('#myDropdown').on('show.bs.dropdown', function () {
    call you read method here..
 })

希望对您有所帮助。

https://jsbin.com/fayoda/edit?html,js,console,output