您的位置:首页 > Web前端 > JavaScript

javascript基础-实现简单功能

2016-07-30 10:46 441 查看
静态页面
(1)打印菱形,并将系统时间打印出来


(2)打印乘法口诀表<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
    function Demo(){
for(i=1;i<=9;i++){
for(j=1;j<=i;j++){
document.write(i+"*"+j+"="+i*j+"   ");
}
document.write("<br>");
}
}
Demo();
</script>
</head>

<body>
</body>
</html>



动态页面
(1)计算个人所得税
[code=html;toolbar:false"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
  function show(){
  var txta=document.getElementById("txt1");
  var txtb=document.getElementById("txt2");
  var txtc=document.getElementById("txt3");
  if(txta.value>txtb.value){
  txtc.value=(txta.value-txtb.value)*0.1;
  }else{
  txtc.value=0;
  }
  }
 function rewrite(){
  var txta=document.getElementById("txt1").value="";
  var txtb=document.getElementById("txt2").value="";
  var txtc=document.getElementById("txt3").value="";
 } 
 show(); 
</script>
</head>

<body>
<table width="419" border="1">
  <tr>
    <td colspan="2"><div align="center">个人所得税计算器</div></td>
  </tr>
  <tr>
    <td width="189"><div align="left">请输入你的月收入:</div></td>
    <td width="214"><input id="txt1" name="txt1" type="text" />
       元</td>
  </tr>
  <tr>
    <td><div align="left">请输入所得税起征额:</div></td>
    <td><input id="txt2" name="txt2" type="text" />
     元</td>
  </tr>
  <tr>
    <td>所得税:</td>
    <td><input id="txt3" name="txt3" type="text" />
     元</td>
  </tr>
  <tr>
    <td colspan="2">
    <center>
      <button name="btn1" value="计算" type="button" onclick="show()">计算
      </button>
      <button name="btn2" value="重填" type="button" onclick="rewrite()">重填
      </button></td>
    </center>
  </tr>
</table>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: