2016 - 1 - 27 javaScrip初步
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016 - 1 - 27 javaScrip初步相关的知识,希望对你有一定的参考价值。
<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初步的主要内容,如果未能解决你的问题,请参考以下文章