[英]Adding a popover to an input box with a button (angularJS)
My goal is to have a button that on click will show a popover "Hello World" on the input box 我的目标是要有一个按钮,单击该按钮后,输入框上将显示一个弹出式窗口“ Hello World”
Currently when clicking on input box itself, the popover will show, but not through the button. 当前,当单击输入框本身时,将显示弹出窗口,但不会通过按钮显示。 Please check my fiddle
请检查我的小提琴
What are some ways to trigger a popover over the input with a button ? 有什么方法可以通过按钮触发输入上的弹出窗口? I tried adding a popover-trigger on the button, but was not sure what value I should use inside it
我尝试在按钮上添加一个popover触发器,但不确定在其中应使用什么值
angular.module('ui.bootstrap.demo', ['ui.bootstrap']); angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope) { });
<!doctype html> <html ng-app="ui.bootstrap.demo"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script> <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.2.js"></script> <script src="example.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div ng-controller="PopoverDemoCtrl"> <p> <button class="btn btn-default">Mouseenter</button> </p> <input type="text" value="Click me!" popover="hello world" class="form-control"> </div> </body> </html>
Below are some additions to your snippet which will trigger the pop over when you click the button, but a few things here should be noted: 以下是您的摘录中的一些新增内容,这些内容会在您单击按钮时触发弹出式窗口,但应注意以下几点:
Hope this helps. 希望这可以帮助。
angular.module('ui.bootstrap.demo', ['ui.bootstrap']); angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope, $timeout) { $scope.activateInput = function () { var elm = document.getElementsByTagName("input")[0]; $timeout(function () { angular.element(elm).triggerHandler('click'); }); } });
<!doctype html> <html ng-app="ui.bootstrap.demo"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script> <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.2.js"></script> <script src="example.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div ng-controller="PopoverDemoCtrl"> <p> <button class="btn btn-default" ng-click="activateInput()">Mouseenter</button> </p> <input type="text" value="Click me!" popover="hello world" class="form-control"> </div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.