我尝试使用focus
作为表单上的第一个输入字段。但 它不起作用。当我打电话给attr("id")
时,它可以工作。当我为同一输入调用焦点时,我没有看到任何 结果。我也尝试使用原生Javascript。有谁知道如何修复这个问题 ?focus()在colorbox弹出框内不起作用
10
A
回答
1
使用
$(document).ready(function() {
// focus on the first text input field in the first field on the page
$("input[type='text']:first", document.forms[0]).focus();
});
0
5
你们都误解了问题。当Colorbox打开时,您无法集中输入字段?
...除非您将焦点添加到Colobox onComplete键,例如,
$('#mydiv a').colorbox({ onComplete:function(){ $('form input:first').focus(); }});
你也可以绑定的焦点事件挂钩:
$('#mydiv a').bind('cbox_complete', function(){
$('form input:first').focus();
});
这应该是足够上手。
+1
谢谢,这真的很有用 - 实际上回答了问题的关键方面。 – penfold 2011-11-17 06:05:10
+0
你能解释一下这个代码放在哪里吗? – 2014-12-04 21:13:56
0
我刚刚偶然发现了这个问题。
我认为这是最好有一个$ .colorbox 首战这样的:
function showActionForColorBox(
_url,
_forFocus
) {
$.colorbox(
{
scrolling: false,
href: _url,
onComplete: function() {
idColorboxAjaxIndect1.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect2.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect3.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect4.appendTo($('#cboxOverlay'));
// --> Possible element's ID for focus
if (_forFocus) {
$('#' + _forFocus).focus();
}
return;
},
onCleanup: function() {
// TODO: ?
return;
},
onClosed: function() {
if (shouldReloadPageAfterColorBoxAction) {
// --> Should we reload whole page?
shouldReloadPageAfterColorBoxAction = false; // NOTE: To be sure: Reset.
window.location.reload(false);
}
else if (cbEBillsActionReloadPopup) {
// --> Should we reload colorbox
cbEBillsActionReloadPopup = false;
showActionForColorBox(_url);
}
else if (cbShouldLoadAnotherContentAfterClosed) {
// --> Should we reload colorbox with custom content?
cbShouldLoadAnotherContentAfterClosed = false;
$.colorbox({ html: setupContentForcbShouldLoadAnotherContentAfterClosed });
setupContentForcbShouldLoadAnotherContentAfterClosed = '';
}
return;
}
}
);
return;
}
1
这可能会发生,你的颜色框打开时,它的焦点进至最高的元素,即身体页。使用document.activeElement来查找焦点到哪个元素。然后找到iframe或你的颜色框的ID,然后将焦点设置它
0
您还可以使用
$.colorbox({
...,
trapFocus: false
});
禁用焦点内部颜色框
相关问题
- 1. Colorbox内联不起作用
- 2. 在ColorBox弹出框中应用iScroll
- 3. jQuery Colorbox弹出式窗口中的窗体将不起作用
- 4. jQuery .focus()不起作用
- 5. Angular2 - @HostListener('focus')不起作用
- 6. Angular 2.focus()不起作用
- 7. 在ColorBox模式弹出框内CKEditor出现问题
- 8. 为什么$(“:select”)。focus在$(“:input”)。focus工作时不起作用?
- 9. 弹出框内弹出框不打开
- 10. JQM弹出 - fieldcontain不起作用弹出内
- 11. 将colorbox弹出框转换为正常弹出框
- 12. Qt 4.5 Focus在QLineEdit上不起作用
- 13. document.getElementById('myControl')。focus()在PhoneGap中不起作用
- 14. CKReitor .focus()在instanceReady事件不起作用
- 15. Webview弹出不起作用
- 16. Bootstrap弹出不起作用
- 17. Modal在JavaScript中弹出不起作用
- 18. $ .colorbox({href:“login.php”});在$(this).click()内部不起作用。
- 19. Bootstrap data-trigger =“focus”不起作用
- 20. 为什么focus()方法不起作用?
- 21. jQuery .focus()回调不起作用
- 22. Polymer autogrow textarea focus()不起作用
- 23. ng-click在引导弹出窗口内容中不起作用
- 24. 内容脚本在弹出页面上不起作用
- 25. 用按钮关闭colorbox弹出框并触发确认框?
- 26. Cookie不能在colorbox加载弹出窗口中工作
- 27. 获取Colorbox funcionality而不弹出?
- 28. ColorBox弹出不会触及代码
- 29. jbox里面的colorbox不起作用
- 30. ColorBox - 自动弹出(如何?)
也可以使用'(“:正文:第一”)。焦点();' – diEcho 2011-03-01 12:48:34
谢谢,但这只适用于登录表单。你有任何想法为什么它不能在其他形式$(“input [id = uname]”)。val(“1300”); \t \t $(“input [id = uname]”)。focus();我没有重点领域的价值= 1300 – 2011-03-01 13:14:31
使用表格名称... – diEcho 2011-03-01 13:20:36