本文實(shí)例講述了jQuery實(shí)現(xiàn)的簡單在線計(jì)算器功能。分享給大家供大家參考,具體如下:
先來看看運(yùn)行效果圖:

完整代碼如下:
<!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>jQuery計(jì)算器</title><style type="text/css"><!-- .div{ border:green 1px; border-style:solid; width:300px; text-align:center; } span{ background-color:#CCCCCC; font-size:32px; font-family:"微軟雅黑"; }.input{ border: 1px solid #6666FF;}--></style><style type="text/css"> .div{ border:green 1px; border-style:solid; width:300px; text-align:center; } span{ background-color:#CCCCCC; font-size:32px; font-family:"微軟雅黑"; }.input{ border: 1px solid #6666FF;}</style><script src="jquery-1.7.2.min.js" type="text/JavaScript"></script><script language="javascript"><!--$(document).ready(function() {//傳說中的ready$("form div input:text").addClass("input");//找到form里面div包含的input標(biāo)簽類型為text的元素 jQuery強(qiáng)悍var num1,num2;$("#jia").click(function() {num1=parseFloat($("#num1").val());num2=parseFloat($("#num2").val());$("#reset").val(num1+num2);});$("#jian").click(function() {num1=parseFloat($("#num1").val());num2=parseFloat($("#num2").val());$("#reset").val(num1-num2);});$("#cheng").click(function() {num1=parseFloat($("#num1").val());num2=parseFloat($("#num2").val());$("#reset").val(num1*num2);});$("#chu").click(function() {num1=parseFloat($("#num1").val());num2=parseFloat($("#num2").val());$("#reset").val(num1/num2);});});// --></script></head><body style="text-align:center"><form><div class="div"><div><span>jQuery簡單計(jì)算器</span></div><div>第一個(gè)數(shù):<input type="text" id="num1" ></div><div>第二個(gè)數(shù):<input type="text" id="num2" ></div><div><input type="button" value=" + " id="jia"><input type="button" value=" - " id="jian"><input type="button" value=" * " id="cheng"><input type="button" value=" / " id="chu"></div><div>結(jié)果:<input type="text" id="reset" /></div></div></form></body></html>PS:這里再為大家推薦幾款在線計(jì)算工具供大家參考使用:
在線一元函數(shù)(方程)求解計(jì)算工具:
http://tools.VeVB.COm/jisuanqi/equ_jisuanqi
科學(xué)計(jì)算器在線使用_高級計(jì)算器在線計(jì)算:
http://tools.VeVB.COm/jisuanqi/jsqkexue
在線計(jì)算器_標(biāo)準(zhǔn)計(jì)算器:
http://tools.VeVB.COm/jisuanqi/jsq
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery操作DOM節(jié)點(diǎn)方法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答