如何将焦点设置在出错时弹出窗口的最后一个元素上
How to set focus on the last element for which the window pop ups on error
根据验证检查字段时,如果验证失败,将打开一个弹出窗口。现在,当我关闭弹出窗口时,弹出窗口应该将焦点返回到最后一个元素(以防多个文本字段的多个验证失败)。有什么建议吗?我的代码是:-
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()
相关文章:
- 表追加而不附加最后一个元素
- 无法在Ionic select中预先选择最后一个选项
- 为什么画布形状只在3个画布中的最后一个画布上渲染
- Jquery append oly获取循环Rails中的最后一个elemen
- 如何创建更好的方式来维护基于我的代码访问的最后一个页面
- dataTables-如何自定义分页类型以显示最后一个页码后面的省略号,
- 多维关联数组的最后一个索引
- 无法获取vis.js最后一个或第一个选定的网络节点
- 循环以检查数组中的最后一个图像
- 从输入值中删除最后一个单词
- 尝试使用Javascript正则表达式来获取“&"分隔文本,无论它是否's是最后一个值
- 为什么这个正则表达式不't匹配最后一个字母数字字符
- 如何从多个复选框中获取最后一个值
- 将OnClick函数设置为<ul>,最后一个ul是擦除第一个ul-s
- 使用querySelector()获取最后一个td元素
- 我需要使网络应用程序作为窗口全屏应用程序工作.在IE-11(最后一个)为PC(WIN-7),全屏模式,用一个按钮关闭它
- 如何将焦点设置在出错时弹出窗口的最后一个元素上
- 谷歌地图,只添加最后一个信息窗口
- 调整窗口大小时,获取新宽度和最后一个宽度
- 如何阻止tinyMCE记住最后一个窗口大小?