prototype

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
        <title>Untitled Document</title>
    </head>
    <body onload="ontext()">
    </body>
    <script language="JavaScript" type="text/javascript">
        function prototypeText(){
            var id = '';
        }
        
        function getId(){
            return this.id;
        }
        
        function setId(id){
            this.id = id;
            return this;
        }
        
        prototypeText.prototype.getId = getId;
        prototypeText.prototype.setId = setId;
        
        function text(){
            var obj = new prototypeText();
            obj.setId('dsfasf');
            alert(obj.getId());
        }
        
        function ontext(){
            alert('window.onload....');
        }
        
        if (document.all) {
            window.attachEvent('onload', text());//IE中onload事件
        }
        else {
            window.addEventListener('load', text(), false);//firefox中onload事件
        }
    </script>
</html>

你可能感兴趣的:(html,prototype,IE,firefox)