首页技术为王JavascriptJS入门到精通 第2章 JavaScript基础

JS入门到精通 第2章 JavaScript基础

分类Javascript时间2026-04-04 09:55:35发布信义之树浏览84
导读:一、练习1 1. 源代码<!doctype html> <html> <head> <meta charset="utf-8"> <title>输出红、绿、蓝3种颜色的值</title> </head> &l...

一、练习1

  1. 源代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>输出红、绿、蓝3种颜色的值</title>
</head>

<body>
    <script type="text/javascript">
    document.write("RGB颜色#6699FF的3种颜色的色值分别为:");
    document.write("<p>R:"+0x66);
    document.write("<p>G:"+0x99);
    document.write("<p>B:"+0xff);
    
    </script>
</body>
</html>


2. 运行页面

    https://www.xinyizhishu.top/jsC/sc/2_1/


二、练习2

  1. 源代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>输出科学记数法表示的浮点数</title>
</head>

<body>
    <script type="text/javascript">
    document.write("科学记数法表示的浮点数的输出结果:");
    document.write("<p>");    
    document.write(3e+6);    
    document.write("<br>");
    document.write(3.5e3);    
    document.write("<br>");
    document.write(1.236e-2);        
        
        
    </script>
</body>
</html>

  2. 运行页面

    https://www.xinyizhishu.top/jsC/sc/2_2/


三、练习3

  1. 源代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>输出奥尼尔的中文名、英文名和别名</title>
<style type="text/css">
    *{font-size:18px;}        
</style>
    
    </head>

<body>
    
<script type="text/javascript">
    document.write('<pre>');
    document.write('中文名:沙奎尔·奥尼尔');
    document.write('\n英文名:ShaquilleO\'Neal');
    document.write('\n别名:大鲨鱼');
    document.write('</pre>');    
</script>    
        
</body>
</html>

  2. 运行页面

    https://www.xinyizhishu.top/jsC/sc/2_3/


四、练习4

  1. 源代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>输出球员信息</title>
<style type="text/css">
*{font-size:18px;
  line-height:30px;}
</style>
</head>

<body>
<h1 style="font-size:24px;">科比·布莱恩特</h1>    
<script type="text/javascript">
var alias="小飞侠";
var height=198;
var score=33643;
var achievement="五届NBA总冠军";
var position="得分后卫/小前锋";    

document.write("别名");
document.write(alias);
document.write("<br>身高:");    
document.write(height);    
document.write("厘米<br>总得分:");    
document.write("score");    
document.write("分<br>主要成就:");    
document.write("achievement");    
document.write("<br>场上位置:");    
document.write(position);    

</script>
        
</body>
</html>

  2. 运行页面

    https://www.xinyizhishu.top/jsC/sc/2_4/


















JS入门到精通 第1章 初识JavaScript

游客 回复需填写必要信息