2012-03-07 45 views
0

如果驗證失敗,將彈出一個窗口打開。現在,當我關閉彈出窗口時彈出應返回將焦點集中到最後一個元素(如果多個文本字段有多個驗證失敗)。有什麼建議麼 ? 我的代碼是: -如何將焦點設置在彈出窗口彈出窗口的最後一個元素上

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(); 
} 

回答

0

在你的代碼,使用:

MyPopUpWin(message); <- existing line 
inputs[i].focus() 
+0

@Diodeus ......它的做工精細..........我的整個頁面閃爍一秒鐘......任何想法爲什麼? – rcky 2012-03-07 15:31:44

+0

嘗試在彈出窗口之前放置焦點代碼。這可能會做到這一點。 – 2012-03-07 15:33:50

+0

@Diodeus ....當我關閉彈出窗口,父頁面鏈接不工作....任何建議 – rcky 2012-03-09 06:35:00

相關問題