最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實(shí)現(xiàn)計(jì)算器和計(jì)時(shí)器功能

 更新時(shí)間:2022年07月21日 17:07:43   作者:肖帆咪  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)計(jì)算器和計(jì)時(shí)器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)計(jì)算器和計(jì)時(shí)器的具體代碼,供大家參考,具體內(nèi)容如下

完成簡(jiǎn)單的計(jì)算器

<!DOCTYPE html>
<html>
?? ?<head>
?? ??? ?<meta charset="utf-8">
?? ??? ?<title></title>
?? ??? ?<style type="text/css">
?? ??? ??? ?#box {
?? ??? ??? ??? ?width: 250px;
?? ??? ??? ??? ?height: 200px;
?? ??? ??? ??? ?background-color: #C0C0C0;
?? ??? ??? ?}
?? ??? ??? ?input{
?? ??? ??? ??? ?width: 50px;
?? ??? ??? ??? ?height: 27px;
?? ??? ??? ?}
?? ??? ??? ?#text{
?? ??? ??? ??? ?width: 229px;
?? ??? ??? ?}
?? ??? ?</style>
?? ??? ?<script type="text/javascript">
?? ??? ??? ? ?var num = 0;?
?? ??? ??? ? ?function str(num) {
?? ??? ??? ? ? ?document.getElementById('text').value += document.getElementById(num).value;
?? ??? ??? ? ?}
?? ??? ??? ? ?function eva() {
?? ??? ??? ? ? ?var res = eval(document.getElementById("text").value);
?? ??? ??? ??? ?document.getElementById("text").value = res;
?? ??? ??? ? ?}
?? ??? ??? ? ?function clearNum() {
?? ??? ??? ? ? ?document.getElementById("text").value = null;
?? ??? ??? ? ?}
?? ??? ?</script>
?? ?</head>
?? ?<body>
?? ??? ?<div id="box">
?? ??? ??? ?<table ?cellspacing="0" cellpadding="5px">
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th colspan="4">
?? ??? ??? ??? ??? ??? ?<input type="text" id="text" />
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="7" id="7" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="8" id="8" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="9" id="9" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="+" id="+" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="4" id="4" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="5" id="5" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="6" id="6" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="-" id="-" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="1" id="1" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="2" id="2" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="3" id="3" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="*" id="*" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="0" id="0" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="c" id="c" onclick="clearNum()"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="=" id="=" onclick="eva()"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th>
?? ??? ??? ??? ??? ??? ?<input type="button" value="/" id="/" onclick="str(this.id)"/>
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ?</table>
?? ??? ?</div>
?? ?</body>
</html>

效果圖

制作一個(gè)計(jì)數(shù)器 如圖,點(diǎn)擊開始從1開始計(jì)數(shù),點(diǎn)擊停止,停止計(jì)數(shù),點(diǎn)擊復(fù)位歸0并結(jié)束計(jì)數(shù)

<!DOCTYPE html>
<html>
?? ?<head>
?? ??? ?<meta charset="utf-8">
?? ??? ?<title></title>
?? ??? ?<script type="text/javascript" src="../js/jquery.1.8.3.min.js" charset="UTF-8">

?? ??? ?</script>
?? ??? ?<script type="text/javascript">
?? ??? ??? ?var second = 0;
?? ??? ??? ?var minutes = 0;
?? ??? ??? ?function star() {
?? ??? ??? ??? ?$("#start").attr("disabled", true);
?? ??? ??? ??? ?$("#stop").attr("disabled", false);
?? ??? ??? ??? ?t = setInterval("sum()", 10);
?? ??? ??? ?}

?? ??? ??? ?function sum() {
?? ??? ??? ??? ?if(second != 100){
?? ??? ??? ??? ??? ?second++;
?? ??? ??? ??? ??? ?if(minutes<10){
?? ??? ??? ??? ??? ??? ?if (second < 10 ) {
?? ??? ??? ??? ??? ??? ??? ?$("#text").val("0"+minutes+".0" + second);
?? ??? ??? ??? ??? ??? ?} else if (second < 100) {
?? ??? ??? ??? ??? ??? ??? ?$("#text").val("0"+minutes+"."+second);
?? ??? ??? ??? ??? ??? ?}?
?? ??? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ??? ?if (second < 10 ) {
?? ??? ??? ??? ??? ??? ??? ?$("#text").val(minutes+".0" + second);
?? ??? ??? ??? ??? ??? ?} else if (second < 100) {
?? ??? ??? ??? ??? ??? ??? ?$("#text").val(minutes+"."+second);
?? ??? ??? ??? ??? ??? ?}?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ?second = 0;
?? ??? ??? ??? ??? ?minutes++;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ?}

?? ??? ??? ?function stop() {
?? ??? ??? ??? ?$("#start").attr("disabled", false);
?? ??? ??? ??? ?$("#stop").attr("disabled", true);
?? ??? ??? ??? ?clearInterval(t);
?? ??? ??? ?}

?? ??? ??? ?function res() {
?? ??? ??? ??? ?second = 0;
?? ??? ??? ??? ?minutes = 0;
?? ??? ??? ??? ?$("#text").val("00.00");
?? ??? ??? ??? ?clearTimeout(t);
?? ??? ??? ??? ?$("#start").attr("disabled", false);
?? ??? ??? ??? ?$("#stop").attr("disabled", false);
?? ??? ??? ?}
?? ??? ?</script>
?? ??? ?<style type="text/css">
?? ??? ??? ?#start,
?? ??? ??? ?#res,
?? ??? ??? ?#stop,
?? ??? ??? ?#text{
?? ??? ??? ??? ?border-radius: 25px;
?? ??? ??? ??? ?margin-right: 20px;
?? ??? ??? ?}
?? ??? ??? ?div{
?? ??? ??? ??? ?background-color: aliceblue;
?? ??? ??? ??? ?width: 120px;
?? ??? ??? ??? ?height: 90px;
?? ??? ??? ??? ?margin: auto;
?? ??? ??? ?}
?? ??? ?</style>
?? ?</head>
?? ?<body>
?? ??? ?<div>
?? ??? ??? ?<table >
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th colspan="2"><input type="text" ?style="width:50px; text-align: center; " value="00.00" id="text" /></th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th><input type="button" id="start" style="background-color: #7FFFD4;" value="開始"
?? ??? ??? ??? ??? ??? ??? ?onclick="star()" />
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ?<th><input type="button" id="stop" style="background-color: bisque;" value="停止" onclick="stop()" />
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ?<th colspan="2"><input type="button" id="res" style="background-color: #8A2BE2;" value="復(fù)位"
?? ??? ??? ??? ??? ??? ??? ?onclick="res()" />
?? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ?</tr>
?? ??? ??? ?</table>

?? ??? ?</div>

?? ?</body>
</html>

效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

漳州市| 北安市| 桑日县| 宜城市| 浮梁县| 班戈县| 乾安县| 上林县| 离岛区| 颍上县| 乐都县| 德惠市| 蓝山县| 华容县| 东源县| 谷城县| 获嘉县| 黄浦区| 博野县| 锡林浩特市| 思南县| 滁州市| 抚宁县| 温州市| 邳州市| 安塞县| 滕州市| 融水| 沙田区| 思南县| 繁昌县| 新营市| 宁德市| 景德镇市| 霍林郭勒市| 稻城县| 应用必备| 鞍山市| 开平市| 昌都县| 宜黄县|