提交 e538fbf1 编写于 作者: BQL473's avatar BQL473

更新网页

上级
<!DOCTYPE html>
<html>
<head>
<title>计算器</title>
<meta charset="utf-8">
<script>
var a = new Array(),mode,b = new Array(),c,type,point,checkCookie = false,MBody = new Array(),checkOver = false;
function yunsuan()
{
var ys1,ys2;
ys1 = MArrayToNumber(0);
ys2 = MArrayToNumber(1);
switch(type)
{
case 1:
ys1+=ys2;
break;
case 2:
ys1-=ys2;
break;
case 3:
ys1*=ys2;
break;
case 4:
ys1/=ys2;
break;
default :
break;
}
gl();
read();
a = MNumberToArray(ys1);
Display();
}
function jjcq(Name)
{
type = Name;
c = 1;
point = false;
}
function dianji(value){
if (c == 0) {
if (point) {
a[1] *= 10;
a[1] += value;
} else{
a[0] *= 10;
a[0] += value;
}
} else{
if (point) {
b[1] *= 10;
b[1] += value;
} else{
b[0] *= 10;
b[0] += value;
}
}
Display();
}
function cheng(value){
if (c == 1){
if (point){
b[1] *= value;
} else{
b[0] *= value;
}
}
else{
if (point){
a[1] *= value;
} else{
a[0] *= value;
}
}
Display();
}
function gl(){
a[0] = 0;
b[0] = 0;
a[1] = 0;
b[1] = 0;
mode = 0;
math = 0;
type = 0;
point = false;
c = 0;
}
function Display(){
var zancun1 = new String();
var zancun2 = new String();
var display = new String();
if (c == 1) {
zancun1 = b[0].toString();
zancun2 = b[1].toString();
} else{
zancun1 = a[0].toString();
zancun2 = a[1].toString();
}
if (point) {
display = zancun1.concat(".",zancun2);
} else{
display = zancun1;
}
document.getElementById("nr").innerHTML = display;
return display;
}
function checkM(){
if (!(checkOver)) {
if (document.cookie) {
checkCookie = true;
read();
} else{
checkCookie = false;
document.getElementById("alert").innerHTML = "cookie不可用,因此无法储存内容";
}
checkOver = true;
}
return checkCookie;
}
function M(Mode){
switch(Mode){
case 1 :
if (MBody != null) {
if (c == 1) {
b[0] = MBody[0];
b[1] = MBody[1];
console.log("B:" + b);
} else{
a[0] = MBody[0];
a[1] = MBody[1];
console.log("A:" + a);
}
if (MBody[1] != 0) {
point = true;
}
}
break;
case 2 :
MBody = null;
break;
case 3 :
if (c == 0) {
MBody = a;
} else{
MBody = b;
}
break;
default :
console.error("MMode == " + Mode);
break;
}
if (checkCookie) {
save();
}
Display();
}
function MArrayToNumber(Type){
if (Type == 0) {
var A = a;
if(A[1] != 0){
for(var i = 0;i < A[1].toString().length;i++){
A[0] *= 10;
}
A[0] += A[1];
for(var i = 0;i < A[1].toString().length;i++){
A[0] /= 10;
}
return A[0];
} else{
return A[0];
}
} else if(Type == 1){
var B = b;
if(B[1] != 0){
for(var i = 0;i < B[1].toString().length;i++){
B[0] *= 10;
}
B[0] += B[1];
for(var i = 0;i < B[1].toString().length;i++){
B[0] /= 10;
}
return B[0];
} else{
return B[0];
}
} else{
var C = MBody;
if(C[1] != 0){
for(var i = 0;i < C[1].toString().length;i++){
C[0] *= 10;
}
C[0] += C[1];
for(var i = 0;i < C[1].toString().length;i++){
C[0] /= 10;
}
return C[0];
} else{
return C[0];
}
}
}
function MNumberToArray(MNumber){
var Arr = new Array();
if (Math.floor(MNumber) < MNumber) {
point = true;
Arr = MNumber.toString().split(".");
} else{
Arr[0] = MNumber;
Arr[1] = 0;
}
return Arr;
}
function save(){
if (checkCookie == 0) {
return undefined;
} else{
var date = new Date();
date.setDate(date.getDate() + 365);
document.cookie = "MSave=" + MBody + ";expires=" + date.toGMTString();
return document.cookie;
}
}
function read(){
if (checkCookie == 0) {
return undefined;
} else{
var cA = document.cookie.split(";");
for(var i = 0;i < cA.length;i++){
var ca = cA[i].trim();
if (ca.indexOf("MSave") == 0) {
var c = ca.split("=");
for (var i = 0;i < c.length;i++) {
c[i].trim();
}
var BBody = c[1].split(",");
for (var i = 0;i < BBody.length;i++) {
BBody[i].trim();
}
MBody = BBody;
}
}
return document.cookie;
}
}
function tuige(){
if(c == 0){
if (point) {
a[1] /= 10;
a[1] = Math.floor(a[1]);
if (a[1] == 0) {
point = false;
}
} else{
a[0] /= 10;
a[0] = Math.floor(a[0]);
}
} else{
if (point) {
b[1] /= 10;
b[1] = Math.floor(b[1]);
if (b[1] == 0) {
point = false;
}
} else{
b[0] /= 10;
b[0] = Math.floor(b[0]);
}
}
Display();
}
</script>
<style>
div.fangkuang{
width: 175px;
height: 16px;
border-style: solid;
border-color: #000000;
border-width: 1px;
margin-bottom: 5px;
padding-bottom: 10px;
padding-top: 1.75px;
margin-right: auto;
margin-left: auto;
font-size: 1.5em;
font-family: "sans serif";
}
input[type="button"]
{
background-color: #FFFFFF;
border-style: solid;
border-color: #000000;
border-width: 2px;
border-radius: 4px;
width: 60px;
height: 60px;
text-align: center;
transition-duration: 0.5s;
-webkit-transition-duration: 0.5s;
font-size: 1.375em;
font-family: "sans serif";
}
input[type="button"]:hover
{
background-color: #FFEF00;
}
h1
{
text-align: center;
font-family: "楷体_GB2312";
}
</style>
</head>
<body onload="gl();Display();checkM()" onunload="save()">
<h1>白启龙制作的计算器</h1>
<hr />
<div class="fangkuang" id="nr"></div>
<form style="text-align: center;">
<input type="button" value="MR" onclick="M(1)" />
<input type="button" value="MC" onclick="M(2)" />
<input type="button" value="MS" onclick="M(3)" />
<input type="button" value="&larr;" onclick="tuige()" /><br />
<input type="button" value="7" onclick="dianji(7)" />
<input type="button" value="8" onclick="dianji(8)" />
<input type="button" value="9" onclick="dianji(9)" />
<input type="button" value="+" onclick="jjcq(1)" /><br />
<input type="button" value="4" onclick="dianji(4)" />
<input type="button" value="5" onclick="dianji(5)" />
<input type="button" value="6" onclick="dianji(6)" />
<input type="button" value="-" onclick="jjcq(2)" /><br />
<input type="button" value="1" onclick="dianji(1)" />
<input type="button" value="2" onclick="dianji(2)" />
<input type="button" value="3" onclick="dianji(3)" />
<input type="button" value="*" onclick="jjcq(3)" /><br />
<input type="button" value="0" onclick="cheng(10)" />
<input type="button" value="00" onclick="cheng(100)" />
<input type="button" value="." onclick="point = true" />
<input type="button" value="/" onclick="jjcq(4)" /><br />
<input type="button" value="C" onclick="gl();Display();" style="width: 125px;"/>
<input type="button" value="=" onclick="yunsuan()" style="width: 125px;" />
</form>
<div style="position: absolute;bottom: 0px;width: 99%;text-align: center;" id="alert"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>白启龙</title>
<style>
input {
background-color: #FFFFFF;
border-style: solid;
border-color: #000000;
border-width: 1px;
border-radius: 4px;
margin-right: 2px;
font-size: 24px;
}
input.rgb {
width: 4.5em;
}
input.r {
background-color: #f00;
color: #fff;
}
input.g {
background-color: #0f0;
color: #fff;
}
input.b {
background-color: #00f;
color: #fff;
}
form {
font-size: 24px;
background-color: #FFFFFF;
padding: 5px;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
border-bottom-style: solid;
border-bottom-color: #000000;
border-bottom-width: 2px;
}
div.hgf{
width: 100%;
margin-top: 3px;
margin-left: 72px;
clear: all;
}
div.hg{
width: 4.5em;
border: solid 1px #000000;
float: left;
margin-right: 5px;
}
</style>
<script>
function drawRGB(){
var rgb = new Array();
var rgbE = new Array();
rgbE[0] = document.getElementById("R");
rgbE[1] = document.getElementById("G");
rgbE[2] = document.getElementById("B");
rgbE[0].value = Math.round(rgbE[0].value);
rgbE[1].value = Math.round(rgbE[1].value);
rgbE[2].value = Math.round(rgbE[2].value);
rgb[0] = rgbE[0].value;
rgb[1] = rgbE[1].value;
rgb[2] = rgbE[2].value;
var i = 0;
while (i < rgb.length) {
if (rgb[i] > 255) {
rgb[i] = 255;
rgbE[i].value = 255;
}
if (rgb[i] < 0) {
rgb[i] = 0;
rgbE[i].value = 0;
}
i++;
}
document.body.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
return "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
}
</script>
</head>
<body style="background-color:#ffffff" onload="drawRGB()">
<form>
<h3 style="margin: 0px;text-align: center;">调色盘</h3>
RGB:<input type="number" id="R" class="rgb r" onchange="drawRGB()" />
<input type="number" id="G" class="rgb g" onchange="drawRGB()" />
<input type="number" id="B" class="rgb b" onchange="drawRGB()" />
<div class="hgf">
<div class="hg" id="hgr"></div>
<div class="hg" id="hgg"></div>
<div class="hg" id="hgb"></div>
</div>
</form>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册