您的位置:首页 > Web前端 > JavaScript

FSWD_2_JavaScript

2015-09-22 21:57 651 查看
location

data type

data structure

Events

function

structure

debug

JS既在client side有,也在server side 和 database side有。

location

一般情况,js代码可以放在任何位置。

js库一般放在head里面

js代码一般放在body的最后面

[code]<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- LOAD JS LIBRARIES HERE  -->
    <scrpit src="mycode.js"></scrpit>

</head>
<body>
<!-- your js code here usually   -->
<script>
    function surprise() {
        alert("hello");
    }
</script>
</body>
</html>


data type

number

只有一种表示,可以用科学计数法。

string

boolean

&& || !

object

var

typeof

parseInt

parseFloat

String

data structure

[]

length

join

push

shift

pop

unshift

concat

[code]var a = [1,2,3];
var a = new Array(3);

array.join(separator)
array.length
array.push
array.pop
array.shift
array.unshift
array1.concat(array2)


Events

onload is triggered when the object is loaded.

[code]<body onload="alert('hello');
    alert('hello2')">


function

alert

confirm

prompt

isNaN

[code]<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>

<script>

    alert("alert");

    confirm("confirm");

    var user_name;
    user_name = prompt("what's your name");
    document.write("welcome to my page  "
        + user_name +"!");
</script>

</body>
</html>


random

Math.random

Math.floor

[code]Math.random()*max_value #[0,max_value)


function

[code]<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <script>
        function user_age() {
            age = prompt("input your age");
            return parseInt(age)
        }
        function check_age() {
            if (user_age() < 18)
                alert("go out")
        }
    </script>
</head>

<body onload="check_age()">

</body>
</html>


structure

if else

switch break

while () {};

string.indexof(“text”) location of “text”

do {} while(); does the once at least

local and global variable

如果在函数里面使用了没有被var创建的变量a,a会变成全局变量。

debug

使用chrome中的开发者工具

同时可以在console中输入js代码

console.log()与alert()的区别是用户不可见但是开发者可见。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: