2016 - 1 - 27 javaScrip初步(一)

时间:2021-11-24 17:08:00
<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>