Ionic Framework Popover JQuery addClass
Ionic Framework Popover JQuery addClass
我正在尝试使用以下方法将类添加到弹出窗口中:
$('#popoverbutton').addClass('someclass');
我已经准备好在文档中尝试过它,并通过 onclick="myfunction();" ..
但它只是不会将类添加到模板中的按钮,该按钮将在打开弹出框时调用。
我想这是因为弹出框仍然没有打开,那么我可以在显示弹出框后执行此操作吗?
如何让它在加载弹出窗口后立即运行一些 jquery?
下面是控制器的代码:
$scope.usefulData = {};
$ionicModal.fromTemplateUrl('templates/mypopover.html', {
scope: $scope
}).then(function(modal) {
$scope.modalMypopover = modal;
});
$scope.closeMypopover = function() {
$scope.modalMypopover.hide();
};
$scope.mypopover = function() {
$scope.modalMypopover.show();
};
$scope.doMypopover = function() {
console.log('Doing mypopover');
$timeout(function() {
$scope.closeMypopover();
}, 1000);
};
为什么不采用 Angular 绑定?我的意思是:modal.shown
事件处理程序上设置一个变量,并使用ng-class
根据该值应用特定的类。
请参阅下面的代码片段:
angular.module('ionicApp', ['ionic'])
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
$scope.btnClass = 'button-positive';
$ionicModal.fromTemplateUrl('templates/mypopover.html', {
scope: $scope
}).then(function(modal) {
$scope.modalMypopover = modal;
});
$scope.$on('modal.shown', function() {
$scope.btnClass = 'button-assertive myClass';
});
$scope.closeMypopover = function() {
$scope.modalMypopover.hide();
$scope.btnClass = 'button-positive';
};
$scope.mypopover = function() {
$scope.modalMypopover.show();
};
$scope.doMypopover = function() {
console.log('Doing mypopover');
$timeout(function() {
$scope.closeMypopover();
}, 1000);
};
});
.myClass {
font-weight: bold;
font-style: italic;
color: blue !important;
}
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Modal</title>
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>
<body ng-controller="AppCtrl">
<ion-header-bar class="bar-positive">
<h1 class="title">Popover</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item >
<button class="button button-positive" ng-click="mypopover()">Popover
</button>
</ion-item>
</ion-list>
</ion-content>
<script id="templates/mypopover.html" type="text/ng-template">
<ion-modal-view>
<ion-header-bar class="bar bar-header bar-positive">
<h1 class="title">New Contact</h1>
<button class="button button-clear button-primary" ng-click="closeMypopover()">Cancel</button>
</ion-header-bar>
<ion-content class="padding">
<div class="list">
<label class="item item-input">
<span class="input-label">First Name</span>
<input ng-model="newUser.firstName" type="text">
</label>
<label class="item item-input">
<span class="input-label">Last Name</span>
<input ng-model="newUser.lastName" type="text">
</label>
<label class="item item-input">
<span class="input-label">Email</span>
<input ng-model="newUser.email" type="text">
</label>
<button class="button button-full button-positive" ng-class="btnClass" ng-click="doMypopover()">Ok</button>
</div>
</ion-content>
</ion-modal-view>
</script>
</body>
</html>
相关文章:
- 当选择组中的单选按钮时,jQuery addClass
- jQuery addClass/removeClass转换不是平滑的,而是断断续续的
- jQuery addClass中断延迟,或者jQuery延迟中断CSS转换,或者两者兼而有之
- jQuery AddClass 似乎添加了类,但没有视觉效果
- jQuery addClass/removeClass在调试期间工作,但不能正常执行
- jQuery next().addClass() and prev().addClass() issue
- Jquery ajax addClass issue
- addClass(JS,jQuery)只在首页//店铺模板
- delay()函数不能与jquery中的addClass()函数一起使用
- jQuery: addClass to HTML5 DOM
- 在IE9和jQuery上选择addClass和removeClass
- Jquery日期选择器addclass()不工作
- 当使用jquery单击表行时,选中复选框addclass
- 返回浏览器时保留jQuery addClass
- jQuery.addClass()不起作用
- jquery是转义括号,当括号在变量的值中破坏我的addClass
- Jquery AddClass and RemoveClass
- 类名 javascript 与 addClass jQuery 相同
- addClass jquery loop
- addClass JQuery在IE8中不工作