在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>感谢大家观看,我们下次见
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.
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!!
Touche. Outstanding arguments. Keep up the great effort.
Wow, this post is good, my younger sister is analyzing these things, therefore I am going to let know her.
There's certainly a lot to learn about this topic. I like all the points you've made.
所有文章都令人印象深刻。由衷感谢 带来的灵感。
你 百分百 分享经验。坚持!
不常看到, 这么高质量的内容。谢谢。
@十二使徒岩 哪张图片?
照片令人惊艳。继续保持 心情。