0

I am working on a page that would allow users to enter an edit mode, in which dropdown forms appear when clicking on links, but I would like to disable this when users are not in editing mode. What I need to happen is for the data-dropdown attr to start as "disabled" but then be set to whatever id that corresponds with the form it should open, "drop25" for example. I have tried using both the attr and prop methods but haven't gotten very far. I can get them to start as disabled, but if I try to edit the attribute in a click handler it doesn't seem to work, even when the source says they change.

Here is what I have so far:

$(document).ready(function () {
    $('a').attr('data-dropdown', 'disabled');

    $(document).on("click", ":button.edit", function() {
        //Enter Edit mode
        if (editMode == false) {
            editMode = true;
            //when editing, enable dropdown
            $('a').attr('data-dropdown', 'drop1');
        }
        else {
             //turn off editing mode
             editMode = false;
             //disable dropdown
             $('a').attr('data-dropdown', 'disabled');
         }
    });
});

Does anyone know if what I'm trying to accomplish is possible? Should I instead maybe just use another type of dropdowns?

4

1 回答 1

1

这是我为解决问题所做的

$(document).on('click', 'a', function () {
        if (editMode == false && $('.f-dropdown').hasClass('open')) {
            $(this).trigger('click');
             window.location = $(this).attr('href');
        };

如您所见,我为所有链接添加了一个单击处理程序,如果用户未处于编辑模式并且基础下拉列表已打开(当您单击连接到下拉列表的链接时会发生这种情况),则在链接关闭下拉菜单,然后访问被点击的链接。

于 2013-09-16T19:28:33.257 回答