[英]How display 'dropdown-menu' without submit button?
I would like create and display menu for my element only after click in small button. 我只想在单击小按钮后为元素创建和显示菜单。
I have a small button which run function "doAction" 我有一个小按钮,运行功能“ doAction”
<i class="fa fa-ellipsis-h" ng-click="doAction(\'OpenMenu\', $event)"></i>
In my function 'doAction' a would like fetch position XY from event mouse click and display in this place my menu. 在我的函数“ doAction”中,想要从事件鼠标单击中获取位置XY,并在此位置显示我的菜单。 Almost everything work... I have problem with 'dropdown-menu'. 几乎所有东西都可以工作...我对“下拉菜单”有疑问。 More precisely, i see button discribed above and button from this code (id=test): 更准确地说,我看到上面描述的按钮和此代码中的按钮(id = test):
var menu = angular.element('<div class="dropdown">' +
'<button id="test" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span></button>'+
'<ul class="dropdown-menu">'+
'<li><a href="#">HTML</a></li>'+
'<li><a href="#">CSS</a></li>'+
'<li><a href="#">JavaScript</a></li>'+
'</ul>'+
'</div>');
menu.css({
position: 'absolute',
left: event.clientX,
top: event.clientY,
zIndex: '999'
});
var body = angular.element(document).find('body').eq(0);
body.append(menu);
Now, i have to click on first button 'fa-ellipsis-h' later button "test", and only then i see my menu. 现在,我必须单击第一个按钮“ fa-ellipsis-h”,然后单击“测试”按钮,然后我才能看到我的菜单。 I don't know how remove button 'id = test' from variable "menu" and open menu immediately after the press first button 'fa fa-ellipsis-h'. 我不知道如何在按下第一个按钮“ fa fa-ellipsis-h”后立即从变量“菜单”中删除按钮“ id = test”并打开菜单。
First, are you sure that you need those single quotes escaped in your function? 首先,确定要在函数中转义那些单引号吗? I copied and pasted your HTML into a jsbin, and it immediately failed because of that. 我将HTML复制并粘贴到jsbin中,由于这个原因,它立即失败了。
If I understand what you're asking, you want your menu to open after the first click, instead of after clicking the <i>
element, and THEN clicking the test button. 如果我了解您的要求,则希望您的菜单在第一次单击后打开,而不是在单击<i>
元素后再单击“测试”按钮后打开。
It is working for me here in this bin: working example <i class="fa fa-ellipsis-h" data-ng-click="doAction('OpenMenu', $event)">Menu</i>
在这里,它对我<i class="fa fa-ellipsis-h" data-ng-click="doAction('OpenMenu', $event)">Menu</i>
: 工作示例 <i class="fa fa-ellipsis-h" data-ng-click="doAction('OpenMenu', $event)">Menu</i>
Clicking the immediately opens the menu (I added in some text for those elements, because I don't have the fontawesome library included). 单击立即打开菜单(我为那些元素添加了一些文本,因为我没有包含fontawesome库)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.