Yas*_*ser 4 jquery twitter-bootstrap angularjs
我使用angular bootstrap实现了一个bootstrap模式,工作正常.
这是我用过的代码的plunker链接.
在我的模态中,我只有一个输入字段(文本框)需要由用户填写,并有一个保存和取消按钮.我希望在显示模态时文本框应该具有焦点.
我尝试了autofocus在这种情况下无效的属性.
下面粘贴的是模态上的html.
<div class="modal-header panel panel-heading">
<button type="button" class="close" ng-click="ok()">×</button>
<h4 class="modal-title">Add Project</h4>
</div>
<div class="modal-body">
<input autofocus="autofocus" type="text" class="form-control" id="ProjectName" placeholder="Enter project name here" data-ng-model="ProjectName" tab-index="1"/>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()" tab-index="2">Create</button>
<button class="btn btn-default" ng-click="cancel()" tab-index="3">Cancel</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我如何让它工作?
Sud*_*ere 10
app.directive('focusMe', function($timeout, $parse) {
return {
link: function(scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
console.log('value=',value);
if(value === true) {
$timeout(function() {
element[0].focus();
});
}
});
element.bind('blur', function() {
console.log('blur')
scope.$apply(model.assign(scope, false));
})
}
};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10202 次 |
| 最近记录: |