如何将焦点设置在窗口弹出错误的最后一个元素上 [英] How to set focus on the last element for which the window pop ups on error
本文介绍了如何将焦点设置在窗口弹出错误的最后一个元素上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在根据验证检查字段时,如果验证失败,则会打开一个弹出窗口。现在,当我关闭弹出窗口时,弹出窗口应该将焦点返回到最后一个元素(如果多个验证失败超过一个文本字段)。有什么建议 ?
我的代码是: -
On checking a field against validations, if validation fails , a pop up window is opened.Now when i close the pop up the pop up should return the focus to the last element(in case more than one validation fails for more than one text field). any suggestions ? My code is:-
function submitformFinal(frm) {
var message;
var inputs = frm.getElementsByTagName("input");
for (var i=0; i < inputs.length; i++)
{
if (inputs[i].getAttribute('type') == 'text')
{
if(!checkSpecialChars(inputs[i].value))
{
message = " Special characters found in element = '";
message += inputs[i].getAttribute('name') + "'\n";
// alert(message);
// createPopup(message);
MyPopUpWin(message);
}
}
}
// return true;
}
function checkSpecialChars(fileOnlyName)
{
if ((/[^a-z0-9\.]/gi).test(fileOnlyName)) {
return false;
}
return true;
}
function MyPopUpWin(message) {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var generator = window.open();
document.onclick=function() {
try{
generator.focus();
return false
}
catch(e){}
}
generator.document.write('<html><head><title>Pop uP</title>');
generator.document.write('<p style="color:#C52B27;">');
generator.document.write(message);
generator.document.write('</p>');
generator.document.write('</head><body>');
generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0"> <\/a>');
generator.document.write('</body></html>');
generator.document.close();
}
推荐答案
在您的代码中,使用:
MyPopUpWin(message); <- existing line
inputs[i].focus()
这篇关于如何将焦点设置在窗口弹出错误的最后一个元素上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文