码迷,mamicode.com
首页 > 编程语言 > 详细

2016 - 1 - 27 javaScrip初步(一)

时间:2016-01-28 15:14:44      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

<head>
</head>

<body>
    <!-- The onclick attribute is the code       
             that happens when the element is clicked.       
             The value of the attribute is some      
             javascript code.        
             In this case it creates an alert        
             pop up dialog
    -->
    <h1 id="title" onclick="alert(‘hello‘);" >
            Hello
    </h1>
</body>

<head>
</head>
<body>
    <!--
        In this case the onclick functions
        writes something to the console.
        The console is an object so we use the
        dot (.) notation to call a function
        on it
    -->
    <h1 id="title"
        onclick="console.log(‘hello‘);" >
            Hello
    </h1>
</body>

  I don‘t know does the code " console.log(‘hello‘) " whether means make a object(console) do sth.?

 

 

2.How to use the jQuery

<head>
   <!-- to use jQuery we need to import it like this -->
   <script src=" http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
    <!--
        in this example use use jQuery to
            change the content itself.
            The $ is shorthand for the jQuery function
         We are passing in a CSS selector which
         gets this element by its id.
         The html function sets the html content
         of an element
    -->
    <h1 id="title" onclick="$(‘#title‘).html(‘Goodbye‘);">
        Hello
    </h1>
</body>

 

3.How to define a function in javaScript

<head>
       <script src = "http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head> 

<body>
    <h1 id="title" onclick="sayHello()"> Hello </h1>
</body>
<!--
     the script tag is where you can put
     more complex scripts
-->
<script type="text/javascript">
    
    function sayHello() {
        alert(‘Hello‘);
    };
</script>

 

2016 - 1 - 27 javaScrip初步(一)

标签:

原文地址:http://www.cnblogs.com/BJTUzhengli/p/5166278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!