程序员鸡皮

文章 分类 评论
95 3 22

站点介绍

一名PHP全栈程序员的日常......

重学Javascript基础(一)Javascript基本语法

abzzp 2024-09-19 574 0条评论 前端 JavaScript

首页 / 正文
本站是作为记录一名北漂程序员编程学习以及日常的博客,欢迎添加微信BmzhbjzhB咨询交流......

发布于2024-07-04

在html中嵌入JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <!-- 1.嵌入html内部 -->
  <a href="javascript:alert('百度一下')" onclick="alert('点击百度一下')">百度一下</a>

  <!-- 2.写到script元素中 -->
  <a class="google" href="#">Google一下</a>
  <script>
    const googleEl = document.querySelector(".google")
    googleEl.onclick = function() {
      alert("Google一下")
    }
  </script>

  <!-- 3.单独的JavaScript文件 -->
  <a class="bing" href="#">Bing一下</a>
  <script src="./bing.js"></script>

</body>
</html>

noscript使用方法

在谷歌浏览器中如何禁止使用JavaScript呢,地址栏输入chrome://settings/content/javascript

选择如下所示内容:

然后我们使用如下代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <noscript>
    <h2>您的浏览器不支持JavaScript, 请打开对应渲染或者更换浏览器!</h2>
  </noscript>
  <script>
    // alert("Hello World")
    console.log("Hello World")
  </script>

</body>
</html>

浏览器会显示:您的浏览器不支持JavaScript, 请打开对应渲染或者更换浏览器!;

javascript的三种注释

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
        // 1.单行注释
        // 2.多行注释
        /*
            我是一行注释
            我是另一行注释
        */
        // 3.文档注释 
        /**
         *  和某人打招呼
         * @param {string} name 姓名
         * @param {number} age 年龄
         */
       function sayHello(name,age){

       }

       sayHello()
    </script>
</body>
</html>

console的快速编写方式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        console.log("Hello World")

        // 推荐方式一:log -> enter
        console.log("Hello World")

        // 推荐方式二:react插件 -> clg -> enter
        console.log("Hello World")

        // 函数
        function sayHello(){
            
        }
    </script>
</body>
</html>

感谢大家观看,我们下次见

评论(0)

最新评论

  • fintechbase

    It's not my first time to pay a visit this web page, i am visiting this website dailly and get good facts from here every day.

  • fintechbase

    Hello, i think that i saw you visited my site so i got here to go back the want?.I'm trying to find things to improve my web site!I suppose its adequate to use a few of your concepts!!

  • fintechbase

    Touche. Outstanding arguments. Keep up the great effort.

  • fintechbase

    Wow, this post is good, my younger sister is analyzing these things, therefore I am going to let know her.

  • digital banking

    There's certainly a lot to learn about this topic. I like all the points you've made.

  • 觀景碼頭

    所有文章都令人印象深刻。由衷感谢 带来的灵感。

  • 圣巴托罗梅奥

    你 百分百 分享经验。坚持!

  • 孤懸外海

    不常看到, 这么高质量的内容。谢谢。

  • abzzp

    @十二使徒岩 哪张图片?

  • 十二使徒岩

    照片令人惊艳。继续保持 心情。

日历

2026年01月

    123
45678910
11121314151617
18192021222324
25262728293031

文章目录

站点公告
本站是作为记录一名北漂程序员编程学习以及日常的博客,欢迎添加微信BmzhbjzhB咨询交流......
点击小铃铛关闭
配色方案