Internet Explorer 8中的JQuery问题

Nei*_*ald 4 html javascript jquery internet-explorer-8

以下代码在Firefox中运行良好,但在IE中则不行.我已尝试对标题和脚本调用字符串进行各种调整,但是没有什么能使IE运行脚本.IE中也关闭了所有安全性.

以下代码有什么问题吗?

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Smartube</title>
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <script src="jquery.js" type="text/javascript"></script>
    <script src="tubeutil.js" type="text/javascript"></script>
    <script src="init.js" type="text/javascript"></script>
    <script type="text/javascript">
    function formfocus() {
    document.getElementById('1').focus();
    }
    window.onload = formfocus;
    </script>
    </head>

    <body>



<div class="wrapper">
    <img class="displayed" src="gfx/sb.png">
    <form class="blocks" action="" method="get">
        <p><input type="text"  class="search" id="1" /></p>
        <p><input type="Submit" class="btn" value="" /></p>
        <ul class="reset autocomplete"></ul>
    </form>

    <ul class="reset videos"></ul>

</div>
    </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

n00*_*dle 6

你的代码不是真正的jQuery,它是直接的javascript,但你的问题是W3C标准需要一个ID以字母开头(参见http://www.w3schools.com/tags/att_standard_id.asp).

您可以将脚本编写为jQuery,如下所示:

function formfocus( ) {
    $('#myid').focus( );
}
$(window).load( formfocus );
Run Code Online (Sandbox Code Playgroud)

编辑:好的,我刚刚在IE中测试了以下内容:

HTML:

<div class="wrapper">
 <img class="displayed" src="gfx/sb.png">
    <form class="blocks" action="" method="get">
        <p><input type="text"  class="search" id="my1" value="" /></p>
        <p><input type="Submit" class="btn" value="" /></p>
        <ul class="reset autocomplete"></ul>
    </form>

    <ul class="reset videos"></ul>

</div>
Run Code Online (Sandbox Code Playgroud)

JS:

$(document).ready( function ( ) {
  $('#my1').focus( );
});
Run Code Online (Sandbox Code Playgroud)

这在IE9中有效,所以我认为它也适用于8.测试版本在这里:http://jsbin.com/ipezey/edit#javascript,html

另外,根据thirtydot的回答,此测试版本具有HTML 5 doctype,而您的版本没有.这可能是您问题的根源.