日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

JS實現簡單打字測試

瀏覽:290日期:2024-05-03 09:40:18

本文實例為大家分享了JS實現簡單打字測試的具體代碼,供大家參考,具體內容如下

需求:實現以下的功能

JS實現簡單打字測試

1.有三個小方塊,分別用來當前輸入的錯誤數量、打字的時間和當前的正確率。2.下方是用來顯示測試句子的容器。3.最后是輸入框

具體思路:

點擊輸入文本區域時,開始測試,會根據用戶輸入來統計當前的錯誤數和正確率,時間會減少。當輸完整段句子時,會自動更新下一段句子。當時間為0時,游戲結束,文本框不能再輸入,然后會統計打字速度。

具體代碼如下:

Html部分

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <link rel='stylesheet' href='http://m.b3g6.com/bcjs/index.css' > <title>打字測試</title></head><body> <div class='type_content'> <h3>打字測試</h3> <ul class='type_box'> <li class='error_box'> <p class='error'>錯誤</p> <p class='error_text'>0</p> </li> <li class='time_box'> <p style='margin: 10px;'>時間</p> <p class='time_text'>60s</p> </li> <li class='currcorrect_box'> <p style='margin: 10px;'>當前準確率%</p> <p class='currcorrect_text'>100</p> </li> <li class='type_speed'> <p style='margin: 10px;'>打字速度</p> <p class='type_speed_text'>30個/分</p> </li> </ul> <div class='text_box'>點擊下放文本輸入框開始打字!!!</div> <div class='text_area'> <textarea name='' placeholder='start typing here...' oninput='processCurrentText()' onfocus='startGame()'> </textarea> </div> <button onclick='resetValues()'>重新開始</button> </div> <script src='http://m.b3g6.com/bcjs/index.js'></script></body></html>

CSS部分:

*{ margin: 0; padding: 0;}.type_content{ width: 60%; /* height: 440px; */ border: 1px solid #ccccff; max-width: 600px; margin: 50px auto; border-radius: 8px; position: relative; min-width: 500px;}.type_content h3{ text-align: center; margin: 10px 0px;}.type_box{ list-style: none; width: 90%; height: 100px; /* border: 1px solid black; */ margin: 0 auto; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-around;}.type_box li{ width: 88px; height: 88px; /* border: 1px solid black; */ text-align: center; font-size: 16px; border-radius: 8px; /* color: #fff; */}.error_box{ background-color: #ccffcc; color: red;}.time_box{ background-color: #66ffff; color: #000033;}.currcorrect_box{ background-color: #FFC125; color: #fff;}.type_speed{ background-color: #FF4040; color: #fff; display: none;}.final_correct{ background-color: #E3E3E3; color: #555555; display: none;}.error{ margin: 10px;}.text_box{ width: 80%; /* height: 50px; */ margin: 20px auto 40px auto; /* border: 1px solid black; */ background-color: #D1EEEE; color: #000; border-radius: 6px; /* text-align: center; */ line-height: 40px; padding: 0px 5px; /* box-sizing: border-box; */}.text_area{ width: 80%; height: 100px; margin: 0px auto; padding-bottom: 50px; margin-bottom: 30px; }#textarea_box{ resize:none; width: 100%; height: 100%; padding: 6px 10px; font-size: 16px; border-radius: 6px; outline: none; border: none; border: 2px solid #eee;} .incorrect_char { color: red; text-decoration: underline; } .correct_char { color: #9B30FF; } .restart{ width: 120px; height: 40px; display: none; border: none; outline: none; cursor: pointer; color: #fff; background-color: #9900ff; border-radius: 6px; position: absolute; bottom: 10px; left: 50%; margin-left: -60px; }

JS部分:

//定義測試時間var testTime = 60;//定義測試的句子var testSentence = [ 'Push yourself, because no one else is going to do it for you.', 'Failure is the condiment that gives success its flavor.', // 'Wake up with determination. Go to bed with satisfaction.', // 'It’s going to be hard, but hard does not mean impossible.', // 'Learning never exhausts the mind.', // 'The only way to do great work is to love what you do.']//定義dom//1.錯誤domvar error_text = document.querySelector(’.error_text’);//2.時間domvar time_text = document.querySelector(’.time_text’);//3.當前正確率var currcorrect_text = document.querySelector(’.currcorrect_text’);//4.打字速度var type_speed_text = document.querySelector(’.type_speed_text’);//打字速度父domvar type_speed = document.querySelector(’.type_speed’);//句子domvar text_box = document.querySelector(’.text_box’);//輸入var textarea_box = document.querySelector(’#textarea_box’);//按鈕var restart = document.querySelector(’.restart’)var timeLeft = testTime;//當前句子var currentSentence = '';//默認開始是索引為0var startIndex = 0;//錯誤統計var errors = 0;var characterTyped = 0;//總錯誤var total_errors = 0; var timer = null;var timeElapsed = 0; //已用時間var accuracy = 0;//正確個數//更新渲染句子function updateSentence(){ text_box.textContent = null; currentSentence = testSentence[startIndex]; //句子拆分 var newChar = currentSentence.split(’’); for(var i = 0; i < newChar.length; i++){ var charSpan = document.createElement(’span’); charSpan.innerText = newChar[i]; text_box.appendChild(charSpan) } if(startIndex < testSentence.length - 1){ startIndex++; }else{ startIndex = 0 }}//輸入當前正確的句子function processCurrentText(){ curr_input = textarea_box.value; curr_input_array = curr_input.split(’’); // console.log(curr_input_array); characterTyped++; errors = 0; quoteSpanArray = text_box.querySelectorAll(’span’); // console.log(quoteSpanArray); quoteSpanArray.forEach((char,index)=>{ var typeChar = curr_input_array[index]; //當前沒有輸入 if(typeChar == null){ char.classList.remove(’correct_char’); char.classList.remove(’incorrect_char’); }else if(typeChar === char.innerText){ //正確的輸入 char.classList.add(’correct_char’); char.classList.remove(’incorrect_char’); }else{ //不正確的輸入 char.classList.add(’incorrect_char’); char.classList.remove(’correct_char’); errors++; } }) error_text.textContent = total_errors + errors; console.log(characterTyped) console.log(error_text.textContent) var correctCharacters = (characterTyped - (total_errors + errors)); var accuracyVal = ((correctCharacters / characterTyped) * 100); console.log(accuracyVal) currcorrect_text.textContent = Math.round(accuracyVal); //輸入結束 if(curr_input.length == currentSentence.length){ updateSentence(); total_errors += errors; textarea_box.value = '' }}//開始游戲function startGame(){ resetValues(); updateSentence(); // clear old and start a new timer clearInterval(timer); timer = setInterval(updateTimer, 1000); }//重新開始function resetValues(){ timeLeft = testTime; timeElapsed = 0; errors = 0; total_errors = 0; accuracy = 0; characterTyped = 0; startIndex = 0; textarea_box.disabled = false; textarea_box.value = ''; text_box.textContent = ’Click on the area below to start the game.’; currcorrect_text.textContent = 100; time_text.textContent = timeLeft + ’s’; type_speed.style.display = ’none’; }//更新時間function updateTimer() { if (timeLeft > 0) { // decrease the current time left timeLeft--; // increase the time elapsed timeElapsed++; // update the timer text time_text.textContent = timeLeft + 's'; } else { // finish the game finishGame(); } } //游戲結束 function finishGame() { // stop the timer clearInterval(timer); // disable the input area textarea_box.disabled = true; // show finishing text text_box.textContent = '可點擊下方按鈕重新開始!!!'; // display restart button restart.style.display = 'block'; // calculate cpm and wpm console.log(characterTyped,timeElapsed) cpm = Math.round(((characterTyped / timeElapsed) * 60)); // update cpm and wpm text type_speed_text.textContent = cpm + ’個/分’; // display the cpm and wpm type_speed.style.display = 'block'; }

測試效果圖:

JS實現簡單打字測試

JS實現簡單打字測試

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产一区二区三区四区五区| 欧美日韩1区| 国产极品模特精品一二| 日韩影院在线观看| 激情五月色综合国产精品| 韩国精品主播一区二区在线观看| 精品国产亚洲一区二区在线观看| 国产精品网站在线看| 午夜电影亚洲| 日韩欧美一区二区三区在线观看| 奇米亚洲欧美| 日韩区一区二| 国产精品久久久久久久久久齐齐 | 色婷婷狠狠五月综合天色拍| 激情黄产视频在线免费观看| av在线资源| 九色精品91| 亚洲精品影视| 麻豆精品视频在线| 丝袜美腿高跟呻吟高潮一区| 亚洲免费观看高清完整版在线观| 日本久久一区| 成人在线黄色| 青青青免费在线视频| 久久精品国产网站| 久久亚洲道色| 国产综合色产| 视频一区日韩| 另类专区亚洲| 麻豆精品网站| 国产精品二区不卡| 亚洲性视频在线| 日本黄色精品| 综合国产在线| 成人午夜精品| 国产精品亚洲综合在线观看| 国产+成+人+亚洲欧洲在线| 好吊日精品视频| 久久精品国产久精国产| 亚洲欧美日韩国产一区| 亚洲精品在线a| 好看的av在线不卡观看| 精品午夜视频| 国产日韩一区二区三区在线播放| 欧美69视频| 国产精品久久观看| 亚洲乱码久久| 日韩视频二区| 日韩精品1区| 美女久久99| 欧美日韩18| 少妇精品久久久| 国产成人精品福利| 国产麻豆一区二区三区| 免费在线看一区| 精品国产黄a∨片高清在线| 亚洲精品看片| 视频在线观看一区| 91高清一区| 黄色成人在线网址| 日韩欧美一区二区三区在线观看| 国产精品jk白丝蜜臀av小说| 蜜桃av一区二区| 亚洲综合国产| 爽好多水快深点欧美视频| 视频一区二区国产| 喷白浆一区二区| 亚洲乱码视频| 日本视频在线一区| 国产精品白丝久久av网站| 无码日韩精品一区二区免费| 色狠狠一区二区三区| 国产亚洲一区| 欧美国产日韩电影| 麻豆国产在线| 久久亚洲成人| 另类av一区二区| 国产麻豆一区二区三区| 久久精品理论片| 精品国内亚洲2022精品成人 | 91亚洲一区| 久久99伊人| 中文字幕在线视频久| re久久精品视频| 日韩午夜黄色| 91精品啪在线观看国产爱臀| 国产欧美久久一区二区三区| 精品国产一区二区三区性色av| 色吊丝一区二区| 日韩激情精品| 欧美日韩精品免费观看视完整| 国产亚洲一级| 久久免费福利| 国产精品普通话对白| 国产精品尤物| 国产亚洲在线| 精品深夜福利视频| 蜜桃91丨九色丨蝌蚪91桃色| 欧美国产先锋| 欧美性感美女一区二区| 日本高清久久| 欧美网站在线| 精品国产乱码久久久| 日韩精品一区第一页| 精品欧美日韩精品| 日本一区二区中文字幕| 成人日韩在线观看| 国产精品久久乐| 男人操女人的视频在线观看欧美| 久久精品福利| 国产图片一区| 亚洲精选久久| 欧美国产91| 日韩在线视频精品| 日韩一区二区三区四区五区| 99热精品久久| 人在线成免费视频| 91综合久久爱com| 亚洲九九精品| 日韩精品免费一区二区夜夜嗨| 麻豆一区在线| av一区二区高清| 日本在线高清| 亚洲精品影视| 亚洲伊人av| 99成人在线| 蜜桃av一区二区| 久久亚洲在线| 日韩大片在线观看| 国产精品免费精品自在线观看| 麻豆国产精品一区二区三区| 免费久久精品| 国产精品视频一区二区三区 | 91久久中文| 国产欧美大片| 好吊日精品视频| 国产suv精品一区| 亚洲精品免费观看| 91成人网在线观看| 国产色播av在线| 日韩国产欧美在线播放| 日本视频在线一区| 91综合视频| 日韩在线网址| 桃色av一区二区| 日韩高清一区| 久久久人人人| 国产日韩亚洲欧美精品| 成人精品视频| 日韩三区四区| 久久国产精品成人免费观看的软件| 丝袜美腿高跟呻吟高潮一区| 精品国产亚洲一区二区在线观看| 日韩一区精品视频| 日韩高清欧美| 欧美黄页在线免费观看| 精品丝袜在线| 美女精品一区二区| 日本中文字幕不卡| 蜜桃国内精品久久久久软件9| 国产精品一区二区三区av| 香蕉国产精品| 亚洲www啪成人一区二区| 欧美日韩1区| 综合激情一区| 狠狠干成人综合网| 日韩中文欧美| 国产白浆在线免费观看| 欧美一区精品| 日韩1区2区3区| 亚洲三级毛片| 午夜国产欧美理论在线播放| 日韩一区二区中文| 高清一区二区| 日本久久综合| 特黄毛片在线观看| 日本综合字幕| 欧美日韩在线二区| 欧美精选一区二区三区| 在线日韩视频| 午夜电影亚洲| 亚洲无线观看| 国产伦理久久久久久妇女| 国产精品主播| 88xx成人免费观看视频库| 国产高潮在线| 久久精品一区二区三区中文字幕| 麻豆国产91在线播放| 国产91在线精品| 欧美.日韩.国产.一区.二区| 免费在线视频一区| 国产精品一区二区99| 福利一区视频| 国产99久久| 日本综合精品一区| 日韩成人精品一区二区| 亚洲美洲欧洲综合国产一区| 婷婷综合亚洲| 男女男精品视频网| 红桃视频亚洲|