JavaScriptまとめ(四)

3284 ワード




    
        
        
        <style>

        </style>
        <script>
            window.onload = function() {
                    document.getElementById("txtInput").onkeyup = function() {
                        if (event.keyCode == 13) { //13    event      
                            document.getElementById("showDiv").innerHTML = this.value; //this.value textarea   
                        }
                    }
                    document.getElementsByTagName("button")[0].onclick = function() {
                        console.log(this);
                    }
                }
                //BOM
                //            var str="1+1";
                //            console.log(eval(str));//  :2 eval     
                //        window.onload=function(){
                //            document.getElementById();
                //        }
                //        myFun();
                //        function myFun(){
                //            console.log("3",this);
                //        }
                //        window.onload=function(){
                //            console.log("1",this);
                //            document.getElementsByTagName("button")[0].onclick=function(){
                //                console.log("2",this);
                //                myFun();
                //            }
                //        }
                /**
                 *1. DOM   W3C    ; [            ]
                 *2. BOM             DOM
                 *          ;[             ,      ]
                 *3. window   BOM   ,   js   ; 
                 */
        </script>
    

    
        <textarea id="txtInput" cols="30" rows="5"/>
        <!--  5 30  textarea-->
        <button>  this</button>
        <div id="showDiv"/>
    


</code></pre> 
 <pre><code>

    
        <meta charset="UTF-8"/>
        <title/>
        <script>
            window.onload = function(){
            function getDateTime(){
//              clearInterval();
            var date = new Date();
            var year = date.getFullYear();
            var mounth = date.getMonth();
            var week = date.getDay();
            var day = date.getDate();
            var h = date.getHours();
            var m = date.getMinutes();
            var s = date.getSeconds();// 
            var getWeek = [" "," "," "," "," "," "," "];
            document.getElementById("showDiv").innerHTML = year+" "+(mounth+1)+" "+day+" "+"   "+getWeek[week]+" "+h+" "+m+" "+s+" ";
            }
            setInterval(getDateTime,500);//    :      
            
        
            }
        </script>
    
    
        <div id="showDiv" style="width: 400px; height: 200px; border: 1px solid black;"/>
    

</code></pre> 
</article>
                            </div>
                        </div>