JS基础(一)
  aH5iJNmqbh1v 2023年11月02日 27 0
1、JS的两种引用方式

如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试一</title>
    <!-- 下面这个标签可以出现在任何位置!! -->
    <script>
        alert("这是内部脚本!");
    </script>
    <!-- 外部脚本 -->
    <script src="./js/demo1.js"></script>
    
</head>
<body>
    
</body>
</html>
2、JS的输出语句

测试代码如下所示:

<!-- js的输出语句 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试JS输出语句</title>
    <script>
        // 浏览器弹出警告框
        alert("Hello World!");
        // 写入HTML,在浏览器中展示
        document.write("Hello World!");    //可以写入标签
        // 写入浏览器控制台
        console.log("Hello World!");
    </script>
</head>
<body>
    
</body>
</html>
3、JS中的数据类型转换
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //数字字符串转换为数字
        alert(parseInt("123"));     //输出123
        //带字符的数字转换为数字    
        alert(parseInt("123a111")); //输出123
        //开头就是字母的字符串转数字
        alert(parseInt("a111222"));  //输出NaN
    </script>
</head>
<body>
    
</body>
</html>

其他类型转为boolean: Number:0和NaN为false,其他均转为true。 String:空字符串为false,其他均转为true。 Null和undefined:均转为false。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  NHaurzrhyr04   2023年12月23日   80   0   0 htmljQueryhtmljQuery
  BEOpup9HILHT   2023年12月23日   53   0   0 htmljQueryhtmljQuery
aH5iJNmqbh1v
作者其他文章 更多

2023-11-13

2023-11-12

2023-11-02

2023-11-02

2023-11-02

2023-11-02

2023-11-02

2023-11-02

2023-11-02