前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FSWD_2_JavaScript

FSWD_2_JavaScript

作者头像
用户1147754
发布2018-01-02 17:03:31
5190
发布2018-01-02 17:03:31
举报
文章被收录于专栏:YoungGyYoungGy
  • location
  • data type
  • data structure
  • Events
  • function
  • structure
  • debug

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

location

一般情况,js代码可以放在任何位置。 js库一般放在head里面 js代码一般放在body的最后面

代码语言:javascript
复制
<!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

代码语言:javascript
复制
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.

代码语言:javascript
复制
<body onload="alert('hello');
    alert('hello2')">

function

alert confirm prompt isNaN

代码语言:javascript
复制
<!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

代码语言:javascript
复制
Math.random()*max_value #[0,max_value)

function

代码语言:javascript
复制
<!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()的区别是用户不可见但是开发者可见。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • location
  • data type
  • data structure
  • Events
  • function
  • structure
  • debug
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档