我定义了一个 input 为:
<INPUT TYPE="text" class="huge text" name="title" id="txtTitle">然后写了如下js代码:
 <script type="text/javascript">
$(document).ready(
             function(){
             $("#txtTitle").focus();
             }
             )
 </script>可是打开页面后没有定位这个焦点上,为什么呀?

解决方案 »

  1.   

    把js代码放到html代码的下面试试,可能js执行的时候,html还没加载完毕,页面上还没有txtTitle呢
      

  2.   

    jquery 对像, 和js 对象不一样, 不能这么用。
      

  3.   

    应该这样写  $("#txtTitle")[0].focus();
      

  4.   

    以下内容摘自jQuery 1.3 中文参考
    -----------
    focus() 
    概述
    触发每一个匹配元素的focus事件。
    这将触发所有绑定的focus函数,注意,某些对象不支持focus方法。示例
    描述:
    当页面加载后将 id 为 'login' 的元素设置焦点:jQuery 代码:
    $(document).ready(function(){
      $("#login").focus();
    });
      

  5.   

    jQuery有$("#txtTitle").focus()这种用法
    而且我试着是可以的
      

  6.   

    $("#txtTitle")返回的不是数组,试试把js的代码放到</html>后面吧
      

  7.   


    <!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=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("#txtTitle").focus();
    });
    </script>
    </head>
    <body>
    test:<INPUT TYPE="text" class="huge text" name="test" id="test"><br/>
    txtTitle:<INPUT TYPE="text" class="huge text" name="title" id="txtTitle">
    </body>
    </html>
    我做了测试,貌似没有错误啊。IE6,IE7,firefox3,chrome,opera9,safari3.2都没出错。
      

  8.   

    没有问题的,楼主是不是没有引入jQuery.js啊!!