Javascript 笔记与总结(2-15)结构、样式、行为分离

【例】

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <p id="p">改变文字样式</p>                
</body>
<script>
    function t(){
        document.getElementById("p").style.fontWeight = "bold";
    }
    document.getElementById("p").onclick = t;
</script>
</html>      

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <p id="p">改变文字样式</p>                
</body>
<script>
    document.getElementById("p").onclick = function(){
        document.getElementById("p").style.fontWeight = "bold";
    }
</script>
</html>      

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <p id="p">改变文字样式</p>                
</body>
<script>
    document.getElementById("p").onclick = function(){
        this.style.fontWeight = "bold";
    }
</script>
</html>      

 

posted @ 2015-05-02 15:07  nemo20  阅读(256)  评论(0)    收藏  举报
访客数:AmazingCounters.com
2016/05/17 起统计