自动求和的html代码

自动求和的html代码,第1张

代码发给你。PS我

<form action="javascipt:">

<input type="text" id="aval" />

<input type="text" id="bval" />

<input type="text" id="cval" />

<button onclick="calc()">计算</button>

</form>

<script type="text/javascript">

function G(id) {

return document.getElementById(id)

}

function calc() {

var aval = parseInt(G('aval').value)*100

var bval = parseInt(G('bval').value)*100

G('cval').value = bval - aval

}

</script>

我给你看下我自己写的一个计算器的代码吧!你要实现求和的话!必须要用javaScript,下面是代码内容:<html>

<head>

<title>计算器</title>

<style>*{ font-size:12px}

body{ background-color:buttonfaceborder-style:none}

.button{ width:50pxheight:30px}

.button1{ width:90pxheight:30px}

#result{ width:100%cursor:defaulttext-align:right}</style>

<script type="text/javascript">

window.onbeforeunload=function(){return("离开你会后悔的")void(0)<br> }function a(i){

switch(i){

case 11:i="/"break

case 12:i="*"break

case 13:i="-"break

case 14:i="+"break

case 15:i="."break

}

document.getElementById("result").value=document.getElementById("result").value+i

} function calc(){

try{

document.getElementById("result").value = eval(document.getElementById("result").value)

}catch(e){

document.getElementById("result").value = "错误的算式"

}

}</script></head><body style="overflow:auto">

<table border="" bgcolor="#00FF00">

<!--DWLayoutTable-->

<tr>

<td height="20" colspan="4" valign="top"><input name="Input" id="result" size="18"></td>

</tr>

<tr>

<td><input type="button" value=" 7 " id="7" onClick="a(7)" class="button"></td>

<td><input type="button" value=" 8 " id="8" onClick="a(8)" class="button"></td>

<td><input type="button" value=" 9 " id="9" onClick="a(9)" class="button"></td>

<td><input type="button" value=" / " id="/" onClick="a(11)" class="button"></td>

</tr>

<tr>

<td height="25"><input type="button" value=" 4 " id="4" onClick="a(4)" class="button"></td>

<td><input type="button" value=" 5 " id="5" onClick="a(5)" class="button"></td>

<td><input type="button" value=" 6 " id="6" onClick="a(6)" class="button"></td>

<td><input type="button" value=" * " id="*" onClick="a(12)" class="button"></td>

</tr>

<tr>

<td height="25"><input type="button" value=" 1 " id="1" onClick="a(1)" class="button"></td>

<td><input type="button" value=" 2 " id="2" onClick="a(2)" class="button"></td>

<td><input type="button" value=" 3 " id="3" onClick="a(3)" class="button"></td>

<td><input type="button" value=" - " id="" onClick="a(13)" class="button"></td>

</tr>

<tr>

<td height="25"><input type="button" value=" 0 " id="0" onClick="a(0)" class="button"></td>

<td><input type="button" value=" . " id="." onClick="a(15)" class="button"></td>

<td><input name="button" type="button" id="=" value=" = " onClick="calc()" class="button"></td>

<td><input type="button" value=" + " id="+" onClick="a(14)" class="button"></td>

</tr>

</table>

</body>

</html>

HTML是无法实现简单的算术运算的。原因如下:

1、HTML是一种规范,一种标准,它通过标记符号来标记要显示的网页中的各个部分。网页文件本身是一种文本文件,通过在文本文件中添加标记符,可以告诉浏览器如何显示其中的内容(如:文字如何处理,画面如何安排,图片如何显示等)。浏览器按顺序阅读网页文件,然后根据标记符解释和显示其标记的内容,对书写出错的标记将不指出其错误,且不停止其解释执行过程,编制者只能通过显示效果来分析出错原因和出错部位。但需要注意的是,对于不同的浏览器,对同一标记符可能会有不完全相同的解释,因而可能会有不同的显示效果。

2、可以使用JavaScript技术实现网页中简单的算术运算,如:

var a=1 var b=2

document.write(a+b)//结果会在网页中输出3

补充知识:

1、超级文本标记语言是标准通用标记语言下的一个应用,也是一种规范,一种标准,

超文本标记语言 (15张)

它通过标记符号来标记要显示的网页中的各个部分。网页文件本身是一种文本文件,通过在文本文件中添加标记符,可以告诉浏览器如何显示其中的内容(如:文字如何处理,画面如何安排,图片如何显示等)。浏览器按顺序阅读网页文件,然后根据标记符解释和显示其标记的内容,对书写出错的标记将不指出其错误,且不停止其解释执行过程,编制者只能通过显示效果来分析出错原因和出错部位。但需要注意的是,对于不同的浏览器,对同一标记符可能会有不完全相同的解释,因而可能会有不同的显示效果

2、JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在HTML(标准通用标记语言下的一个应用)网页上使用,用来给HTML网页增加动态功能。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7279046.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存