单击事件不在Jquery的引导下拉菜单中触发

时间:2022-08-26 20:49:41

I am trying to create a dropdown menu for a button using jquery and bootstrap but the menu closes as soon as I click on it. There's a textbox inside that button that I need to enter text into.

我正在尝试使用jquery和bootstrap为按钮创建一个下拉菜单,但是一旦我点击它就会关闭菜单。我需要在该按钮内输入文本框以输入文本。

Here's the HTML code:

这是HTML代码:

<a class="btn dropdown-toggle btn-default" data-toggle="dropdown" title="Hyperlink"><i class="fa fa-link"></i></a>
            <div class="dropdown-menu input-append" id = "hyperlink-menu">
                <input class="span2" placeholder="URL" type="text" data-edit="createLink"/>             
                <button class="btn" type="button">Add</button>
            </div>

Here's the Javascript part of it:

这是它的Javascript部分:

$(document).ready(function(){
    $('#hyperlink-menu').click(function(e) {
        alert("Asd");
        e.stopPropagation();
    });
});

I am trying to prevent the menu from closing when someone types into the textbox. This is how the fiddle should look like(Except other buttons ofcourse)

当有人键入文本框时,我试图阻止菜单关闭。小提琴应该是这样的(除了其他按钮)

单击事件不在Jquery的引导下拉菜单中触发

That alert box is not firing! I know this question is sort of redundant but I got the document.ready idea after going through other similar questions! None of them seem to be working!

警报框没有开火!我知道这个问题有点多余,但我在完成其他类似的问题后得到了document.ready的想法!他们似乎都没有工作!

I tried creating a fiddle(http://jsfiddle.net/2ca9hh7g/) but it's really very messed up....

我尝试创建一个小提琴(http://jsfiddle.net/2ca9hh7g/),但它真的很混乱....

1 个解决方案

#1


Setting the click on span2 solved my problem.

设置span2上的点击解决了我的问题。

#1


Setting the click on span2 solved my problem.

设置span2上的点击解决了我的问题。