http://www.railscn.com/viewthread.php?tid=917

解决方案 »

  1.   

    在IE下,html元素根本不是Object的实例!
    因此IE下的html元素根本没有原型!更不要说为原型添加方法了!<!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>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="Gao YiXiang" />
        <meta name="email" content="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    </head>
    <body>
    <input type="text" id="tbxTest" />
        <script type="text/javascript">
        <!--
    var e = document.getElementById("tbxTest");
    alert(e instanceof Object); // IE6 下为 false;FF2 下为 true
        //-->
        </script>
    </body>
    </html>
      

  2.   

    IE下只能通过辅助对象完成对html元素的操作!L@_@K
    <!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>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="Gao YiXiang" />
        <meta name="email" content="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    </head>
    <body>
        <select id="sltTest">
            <option value="" selected="selected">1</option>
            <option value="">2</option>
            <option value="">3</option>
            <option value="">4</option>
            <option value="">5</option>
        </select>
        <script type="text/javascript">
        <!--
    // 辅助对象。
    var SelectHelper = {};
    SelectHelper.getSize = function(oSel)
    {
        if (oSel)
        {
            return oSel.options.length;
        }
    };var o = document.getElementById("sltTest");
    var size = SelectHelper.getSize(o);
    alert(size);
        //-->
        </script>
    </body>
    </html>