var t = document.getElementById('a'+v.value); 
这里加个判断就可以了
if (!t) {你的处理;
         return 0;
         }
或者结合上下内容写成:
var t = document.getElementById('a'+v.value);
if(t){
t.scrollIntoView();
window.focus(); 
}
else {你的处理}

解决方案 »

  1.   

    </head>
    <script language="javascript">
    function s(){
    var v = document.getElementById('text');
    var t = document.getElementById('a'+v.value);
    if (!t) t=document.getElementById('text');
    }
    function b(t){
    t.scrollIntoView();
    window.focus();
    }
    </script>
    <body onload="b(document.getElementById('text'));">
      

  2.   

    </head>
    <script language="javascript">
    function s(){
    var v = document.getElementById('text');
    var t = document.getElementById('a'+v.value);
    if (!t) t=document.getElementById('text');
    b(t);//昨天回复时少写了这句啊,太急了,现在的效果是如果没有就停在输入框那里了。
    }
    function b(t){
    t.scrollIntoView();
    window.focus();
    }
    </script>
    <body onload="b(document.getElementById('text'));">
      

  3.   

    其实我想要这个效果,但是这样弄有个局限性,就是只能用1~~9,我原本是想改成只要定义了的,任何字包括中英文都可以,但是弄不了,直接删了IF那里虽然可以,但是提示窗口就没有了......其实你改的跟我上面的那段效果差不多,不过你真的挺热心的^^Y
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>无标题文档</title> 
    </head> 
    <script language="javascript"> 
    function s(){ 
    var v = document.getElementById('text'); 
    if (/^[1-9]$/.test(v.value)==false){ 
    alert('必须填入1-9的数字'); 
    v.focus(); 
    return false; 

    var t = document.getElementById('a'+v.value); 
    t.scrollIntoView(); 
    window.focus(); 

    </script> 
    <body onload="document.getElementById('text').focus();"> 
    <p>输入1~9的单个数字: 
    <form onsubmit="s();return false"> 
    <input type="text" id="text" value="" /> 
    <input type="submit" value="提交"/> 
    </form> 
    </p> 
    <p><a href="#6">111111111111111</a></p> 
    <p> </p> 
    <p> </p> 
    <p> </p> 
    <p> </p> 
    <p> 
    <a id="a1">1</a></p> 
    <p><br /> 
    <a id="a2">2</a></p> 
    <p><br /> 
    <a id="a3">3</a></p> 
    <p><br /> 
    <a id="a4">4</a></p> 
    <p><br /> 
    <a id="a5">5</a></p> 
    <p><br /> 
    <a id="a6">6</a></p> 
    <p><br /> 
    <a id="a7">7</a></p> 
    <p><br /> 
    <a id="a8">8</a></p> 
    <p><br /> 
    <a id="a9">9</a><br /> 
    </p> 
    <div style="height:3000px;">...</div> 
    </body> 
    </html>
      

  4.   

    你试试这个就知道了,你试查找没定义过的,但我这个有个局限性,就是只能定义1~~9,我想定义成任何中文,不一定要用数字
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>无标题文档</title> 
    </head> 
    <script language="javascript"> 
    function s(){ 
    var v = document.getElementById('text'); 
    if (/^[1-9]$/.test(v.value)==false){ 
    alert('必须填入1-9的数字'); 
    v.focus(); 
    return false; 

    var t = document.getElementById('a'+v.value); 
    t.scrollIntoView(); 
    window.focus(); 

    </script> 
    <body onload="document.getElementById('text').focus();"> 
    <p>输入1~9的单个数字: 
    <form onsubmit="s();return false"> 
    <input type="text" id="text" value="" /> 
    <input type="submit" value="提交"/> 
    </form> 
    </p> 
    <p><a href="#6">111111111111111</a></p> 
    <p> </p> 
    <p> </p> 
    <p> </p> 
    <p> </p> 
    <p> 
    <a id="a1">1</a></p> 
    <p><br /> 
    <a id="a2">2</a></p> 
    <p><br /> 
    <a id="a3">3</a></p> 
    <p><br /> 
    <a id="a4">4</a></p> 
    <p><br /> 
    <a id="a5">5</a></p> 
    <p><br /> 
    <a id="a6">6</a></p> 
    <p><br /> 
    <a id="a7">7</a></p> 
    <p><br /> 
    <a id="a8">8</a></p> 
    <p><br /> 
    <a id="a9">9</a><br /> 
    </p> 
    <div style="height:3000px;">...</div> 
    </body> 
    </html>