卜卜Bobo's profileBobostory *PhotosBlogListsMore Tools Help

Bobo 卜卜

Photo 1 of 1
More albums (1)

Bobostory *

—enjoy every day—

JavaScript权威指南1-5

javascript:5%2
javascript:x = 3; (x < 5)? "x is less": "x is greater"
javascript:d = new Date(  ); typeof d;
javascript:for(i=0,j=1,k=0,fib=1; i<10; i++,fib=j+k,k=j,j=fib) alert(fib);
javascript:s=""; for(i in document) s+=i+":"+document[i]+"\n"; alert(s);

JavaScript权威指南1-4

<!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=gb2312" />
<title></title>
<script language="JavaScript">
 document.write("<h2>Table of Fibonacci Numbers</h2>");
 for (i=0, j=1, k=0, fib =0; i<50; i++, fib=j+k, j=k, k=fib){
  document.write("Fibonacci ("  + i +  ") = " + fib);
  document.write("<br>");
 }
</script>
</head>
<body>
</body>
</html>

JavaScript权威指南1-3

<!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=gb2312" />
<title>JavaScript Loan Calculator</title>
</head>
<body bgcolor="#FFFFFF">
<!--
以下是一个HTML表单,用户可以用它输入数据,
JavaScript则可以用它把计算的结果显示给用户。
表单元素嵌套在一个表中,这样可以美化它们的外观。
表单自身名为“loandata”,表单中的域名为“interest”和“years”。
表单后的JavaScript代码使用了这些域名。
注意,有些表单元素定义了“onchange”或“onclick”事件处理器。
它们定义了用户输入数据或点击按钮时要执行的JavaScript代码串。
-->
<form name="loandata">
 <table>
  <tr>
   <td colspan="3"><b>Enter Loan Information:</b></td>
  </tr>
  <tr>
   <td>1)</td>
   <td>Amount of the loan (any currency):</td>
   <td><input type="text" name="principal" size="12" onchange="calculate();"></td>
  </tr>
  <tr>
   <td>2)</td>
   <td>Annual percentage rate of interest:</td>
   <td><input type="text" name="interest" size="12" onchange="calculate();"></td>
  </tr>
  <tr>
   <td>3)</td>
   <td>Repayment period in years:</td>
   <td><input type="text" name="years" size="12" onchange="calculate();"></td>
  </tr>
  <tr>
   <td colspan="3"><input type="button" value="Compute" onclick="calculate();"></td>
  </tr>
  <tr>
   <td colspan="3"><b>Payment Information:</b></td>
  </tr>
  <tr>
   <td>4)</td>
   <td>Your monthly payment will be:</td>
   <td><input type="text" name="payment" size="12"></td>
  </tr>
  <tr>
   <td>5)</td>
   <td>Your total payment will be:</td>
   <td><input type="text" name="total" size="12"></td>
  </tr>
  <tr>
   <td>6)</td>
   <td>Your total interest payments will be:</td>
   <td><input type="text" name="totalinterest" size="12"></td>
  </tr>
 </table>
</form>
<!--
以下是使本例运行的JavaScript程序。
注意该脚本定义的calculate()函数,它由表单中的事件处理器调用,
该函数用上面的HTML代码中定义的名字引用表单中的域的值。
-->
<script language="JavaScript">
function calculate() {
 //从表单中获得用户输入的数据。假定它们完全有效。
 //把利息从百分比转换成十进制数。
 //把年利率转换成月利率。
 //把年支付额转换成月支付额。
 var principal = document.loandata.principal.value;
 var interest = document.loandata.interest.value / 100 / 12;
 var payments = document.loandata.years.value * 12;
 //下面计算月支付额,使用了很少的数学函数。
 var x = Math.pow(1 + interest, payments);
 var monthly = (principal*x*interest)/(x-1);
 //检查结构是否是无穷大的数。如果不是,就显示结果。
 if (!isNaN(monthly) && (monthly != Number.POSITIVE_INFINITY) &&(monthly != Number.NEGATIVE_INFINITY)) {
  document.loandata.payment.value = round(monthly);
  document.loandata.total.value = round(monthly * payments);
  document.loandata.totalinterest.value = round((monthly * payments) - principal);
 }
 //否则,用户输入的数据是无效的,因此什么都不显示。
 else {
  document.loandata.payment.value = "";
  document.loandata.total.value = "";
  document.loandata.totalinterest.value = "";
 }
}
//以下是个简单的方法,它将把数字舍入成两位小数的形式。
function round(x) {
 return Math.round(x*100)/100;
}
</script>
</body>
</html>

JavaScript权威指南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=gb2312" />
<title></title>
</head>
<body>
<form>
 <input type="button" value="Click here" onclick="alert('You clicked the button');">
</form>
</body>
</html>

JavaScript权威指南1-1

<!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=gb2312" />
<title>Factorials</title>
<script language="JavaScript">
 document.write("<h2>Table of Factorials</h2>");
 for(i=1,fact=1;i<10;i++,fact*=i)
 {
  document.write(i+"!="+fact);
  document.write("<br>");
 }
</script>
</head>
<body>
</body>
</html>
 
感谢访问!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.