JavaScript 制作简单计算器 isNaN eval 使用
判断(value)是否是一个数字,假如值是NaN那么IsNan返回TRUE,否则返回FALSE。
还有一种办法,变量可以与它自身进行比较。 假如比较的结果不等,那么它就是 NaN 。
这是因为 NaN 是唯一与自身不等的值。
第一种方法:
<html>
<head>
<title>简单计算器的制作</title>
</head>
<mce:script language="JavaScript"><!--
function say(){
var one = parseInt(document.getElementById("one").value);//将文本内容转换数值
var two = parseInt(document.getElementById("two").value);
var flag = document.getElementById("flag").value;
if(isNaN(one)){ //isNan判断是否为数字
alert('请输入数字');
}else if(isNaN(two)){
alert('请输入数字');
}else{
var sum = 0;
switch(flag){
case "+":
sum = one + two;
break;
case "-":
sum = one - two;
break;
case "*":
sum = one * two;
break;
case "/":
sum = one / two;
break;
}
document.getElementById("result").innerHTML = "<font color=red>" + sum + "</font>"
}
}
<body>
<input type="text" name="one" id="one">
<select name="flag" id="flag">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="two" id="two">
<input type="button" value="=" onClick="say()">
<!--
<input type="text" name="result" id="result">
-->
<span id="result"></span>
</body>
</html>
<html>
<head>
<title>简单计算器的制作</title>
</head>
<mce:script language="JavaScript"><!--
function say(){
var one = parseInt(document
相关文档:
<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table ......
This document is for establishing build standard for JavaScript and CSS compression
The objective for this document is to establish a companywide JavaScript and CSS compression standard that can be shared crossing multiple SharePoint product development projects. This is the first draft
Overview ......
<!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>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
......
(function() {
var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63 ......