<!DOCTYPE>
<html>
<head>
<!--注意两个标签之间不能有任何内容,否则会导致页面失效-->
<script src="my.js"></script>
</head>
<body>
<!--行内JS-->
<button onclick="alert('努力,奋斗')">点击触发页面弹窗</button>
<!--内部JS一般放在body内部的末尾,因为会影响后面其他类型标签的渲染-->
<!--script 标签是按照出现的位置执行的-->
<script>
alert('努力,奋斗');
</script>
</body>
</html>
<!--外部 js 文件-->
alert('努力,奋斗')
<script>
alert('你好 JS~')
document.write('JavaScript 我来了!')
console.log('它~会魔法吧~')
</script>
<script>
let num = 20;
let uname = '张三';
console.log(`num = ${num}, uname = ${uname}`);
</script>
<script>
let name;
name = prompt('请输入姓名:');
document.write('您的姓名为: ' + name);
</script>
<script>
let num1 = 10;
let num2 = 20;
let temp = num1;
num1 = num2;
num2 = temp;
document.write(`num1 = ${num1}, num2 = ${num2}`);
</script>
<script>
let uname, age, gender;
uname = prompt('请输入您的姓名:');
age = prompt('请输入您的年龄:');
gender = prompt('请输入您的性别:');
document.write(`uname = ${uname}, age = ${age}, gender = ${gender}`);
</script>
<script>
let week = [
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六',
'星期日',
]
document.write(week[6]);
</script>
<script>
const pi = 3.14;
let area;
let r = prompt('请输入半径');
are = pi * r * r;
document.write('圆的面积为:'+area);
</script>
<script>
let uname, age;
uname = prompt('请您输入姓名');
age = prompt('请您输入年龄');
document.write(`大家好,我叫${uname},今年${age}岁了`);
</script>
<script>
let num1, num2;
num1 = prompt('请输入第一个数');
num2 = prompt('请输入第二个数');
document.write(`sum = ${Number(num1) + parseInt(num2)}`);
</script>
<script>
let price, num, address;
price = prompt('请输入商品价格:');
num = prompt('请输入商品数量:');
address = prompt('请输入收货地址:');
document.write(`price = ${price}, num = ${num}, address = ${address}`);
</script>
<!DOCTYPE>
<html>
<head>
<style>
h2 {
text-align: center;
}
table {
/* 合并相邻边框 */
border-collapse: collapse;
height: 80px;
margin: 0 auto;
text-align: center;
}
th {
padding: 5px 30px;
}
table,
th,
td {
border: 1px solid #000;
}
</style>
</head>
<body>
<h2>订单确认</h2>
<script>
let price, num, address;
price = prompt('请输入商品价格:');
num = prompt('请输入商品数量:');
address = prompt('请输入收货地址:');
let sum = price * num;
document.write(`
<table>
<tr>
<th>商品名称</th>
<th>商品价格</th>
<th>商品数量</th>
<th>总价</th>
<th>收货地址</th>
</tr>
<tr>
<td>小米手机青春PLUS</td>
<td>${price}元</td>
<td>${num}</td>
<td>${sum}元</td>
<td>${address}</td>
</tr>
</table>
`);
</script>
</body>
</html>
标签:prompt,入门,num2,第一节,alert,let,JS,输入,num1
From: https://www.cnblogs.com/20200109-zwh/p/17639580.html