- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 Angular,特别是带有 Bootstrap 模块的 Angular(现在谁可以没有 Bootstrap 生活?)。
无论如何,是否有人有一个干净的解决方案来将焦点设置在弹出的新模式对话框中的输入字段上?这个基本功能似乎不支持开箱即用。我以为我可以在“开放”的 future 勾搭 - 但似乎被提前叫到了。
因此,当您打开模态实例时 - 例如
$modal.open({
"templateUrl": 'myModalContent.html',
"controller" : 'modalInstanceCtrl',
"size": size,
"resolve" : {
"items": function () {
return $scope.items;
}
}
});
然后,您可以将模态实例与广播偶数等一起使用:
modalInstance.opened.then(function(){
$rootScope.$broadcast(myNewDirectiveBootstrapConfig.events.modalInstanceOpened
, modalInstance);
});
现在我想要关注的输入元素将通过指令进行 Angular 增强。
<label for="popupTitle">Title:</label>
<input type="text" class="form-control" id="popupTitle"
ng-required="true"
ng-model="popup.title"
ng-minlength="1"
newdirective-modal-focus
>
指令代码将是非侵入性的并且独立于页面逻辑。理想情况下,您将只使用事件 API,并且您的非侵入式指令将被调用并执行焦点魔法。
angular.module('newDirectivesModule', [])
.constant('myNewDirectiveBootstrapConfig', {
events: {
modalInstanceOpened : "modalInstanceOpened"
}
})
.directive('newdirectiveModalFocus', ['myNewDirectiveBootstrapConfig',
function (myNewDirectiveBootstrapConfig) {
return {
restrict:'A', // process compile directive only on element attributes
link: function(scope, elm, attr) {
scope.$watch(function(){return elm.is(":visible");}, function(value) {
if(elm.is(":visible")){
elm.focus();
}
});
scope.$on(myNewDirectiveBootstrapConfig.events.modalInstanceOpened, function(event, data) {
if(elm.is(":visible")){
elm.focus();
}
});
}
};
}]);
您可以在代码中看到我玩过不同的观看场景。实际情况是,指令代码正在被调用给儿子。opens.then future 似乎会发布事件,表明模型在您实际看到屏幕上 float 的模式对话框之前已打开。输入元素被告知要设置焦点 - 但显然很快,如果我调试,当调用 focus() 时它仍然在后台。它是可见的,因为您可以在页面的 dom 中进行查找,并且如果您询问 JQuery(":visible") dom 元素,它确实是可见的。但肉眼仍然看不见。
我在其他地方看到过一种与我的完全不同的方法,它不依赖于事件,而是依赖于属性值从 true 变为 false。我根本不喜欢这个方法,因为它与页面的业务逻辑耦合太多,我不喜欢并拒绝将其作为解决方案。
解决这个问题的方法应该完全依赖于这样一个事实:模式对话框的主体中只有一个输入元素,并且设置了“请关注我,请”指令,并尽可能与页面逻辑分离。
理想情况下,这应该是 Bootsrap Angular 本身支持的功能,遗憾的是似乎并非如此,但由于我们必须 - 在任何情况下 - 使用 API 来 OEPN 对话框并关闭它们,所以我们应该能够扩展此步骤以横切干净的方式获得焦点功能。
对此有什么建议吗?
最佳答案
我使用不同的指令方式来获取焦点发布链接
以确保元素被渲染(无论是否为模态):
app.directive('focusMe',
['$timeout',
function ($timeout) {
return {
link: {
pre: function preLink(scope, element, attr) {
// ...
},
post: function postLink(scope, element, attr) {
$timeout(function () {
element[0].focus();
}, 0);
}
}
}
}]);
所以输入应该如下所示:
<input type="text"
focus-me
class="form-control" id="popupTitle"
ng-required="true"
ng-model="popup.title"
ng-minlength="1">
<小时/>
中的演示 Plunker
关于javascript - Angular ui-bootstrap-tpls-0.12.1 打开模态对话框设置焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29999753/
我需要一些帮助。这都是关于选项卡索引的。我有一个使用 document.getElementById("name").focus(); 的 JavaScript,其中 id="name"的 textb
这是我的第一篇文章,如果您想了解更多信息,请告诉我! 我正在使用选择列表和 jQuery Accordion 。当用户从列表中选择一个值时,它会使用 activate 方法打开折叠面板的相关部分。 除
JQM 1.3.2/ASP.NET MVC 4 当选择一个值时,焦点没有正确设置到输入字段,我错过了什么? 周围的典型 jqm-shadow 没有从选择中移除,输入得到阴影效果,但光标没有设置到输入字
我正在为 Android 开发一个播放列表应用程序,它有一个包含歌曲名称 (TextView) 作为其列表项的 ListView。 随着歌曲的播放,我想突出显示 ListView 中的项目,直到歌曲结
我在这里不知所措,以前从来没有遇到过这个问题。 我无法让 focus() 在任何浏览器中工作。我正在使用 jquery,甚至不能让它与标准的 javascript 一起工作。我也尝试添加超时但仍然没有
登录后我有一个文本字段。登录后光标将自动聚焦在该文本字段上。如何验证该文本字段上是否存在光标/焦点? 文本框的HTML代码如下: 最佳答案 您也可以尝试直接的 webdriver 方法: drive
我有一个框架和一个面板。我永久删除面板并添加另一个面板。添加新面板后,我需要 JTextField 来获得焦点。我该怎么做? 我尝试了 panel.requestFocus() 方法,但没有成功。 示
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: Trouble with jquery lavalamp 出于某种原因,无论我点击哪个链接,我的背景颜色都会
在我的表单验证中,在提交时,我正在验证表单,并找到未填充的元素并使用此函数进行聚焦:工作正常 switch (tagName) { case 'TEXT': if (!actualVa
我最近构建了一个 JS/CSS 模态系统。该元素使用的是 Bootstrap 模式,但通过在其中放置无法滚动或无法正确聚焦在移动设备上的表单和大量内容,将其推向了极限。 可以触发模态系统here单击大
我正在建立一个网站,但我想将图片放在背景中,但我无法将其放在我想要的位置。 我希望网页上图像的“焦点”位于图像中心几像素处。宽度我都能看出来,但是高度没有。 图像分辨率为“5760x3840px”。
这个问题在这里已经有了答案: using :focus pseudo class on li or other element else than a,input,button, etc (2 个
每当我创建编辑器的另一个实例(在我的例子中,通过 onkeypress 事件),我就会失去对创建新编辑器时正在输入的编辑器的关注。我怎样才能防止所有编辑都失去对任何事件的关注? 最佳答案 为此,Qui
我试图将焦点放在一个字段上,更改文本的颜色,但无论我尝试什么:它都不起作用。以下是 HTML: .register-section input:focus + .register-section la
我已经为微调器选择的变化设置了一个监听器。在监听器中,我想关注一个 EditText 字段。我使用了以下代码: text_other_msg.setFocusable(true); 它不起作用。我还尝
我在表单屏幕上有几个 UITextField 输入,其中一些有一个数字键盘显示,通过自定义弹出窗口显示。当用户在字段中前进时,我们会根据需要关闭或打开弹出窗口。在 iOS 11 中,似乎“第一响应者”
我在 jQueryUI 中输入焦点时遇到问题。我在按钮上使用了 hover() 方法并且它正在工作,但是输入上的 focus() 不起作用。我不知道为什么。这是代码和 fiddle $(documen
有没有办法在自动对焦完成后随时获取对焦点? 在 Apple 的示例代码中,他们使用: - (void)subjectAreaDidChange:(NSNotification *)notifi
如果我的焦点不在 textField 上,如何移除 NSTextField 上的焦点? 我有一个 NSTextField,我设置了操作:编辑结束时发送。单击 textField 后,当我单击 View
如何通过 jQuery 实现这一点? 当用户单击表单中的任何输入时,它就会获得焦点。当用户从任何输入中单击表单外时,它会变得模糊,但是,在表单本身的输入之间进行 Tab 键切换之间不会触发模糊。 对于
我是一名优秀的程序员,十分优秀!