赞
踩
预览地址:https://yubin.applinzi.com
预览图片:

详细代码:
<!DOCTYPE html> <html> <head> <title>myweb</title> <style> html{ height: 100%; background:url(https://cdn.nlark.com/yuque/0/2019/jpeg/124897/1558635287060-assets/web-upload/074f3bf7-9354-464a-985a-282167e3d212.jpeg); background-size:100% 100%; background-repeat:no-repeat; } div{ width: 300px; margin: 100px auto 0; } .input_box{ width: 100%; height: 100px; outline: none; /*去掉轮廓线*/ border: 10px solid #000; box-sizing: border-box;/*怪异盒模型*/ resize: none;/*禁止拖拽*/ border-radius: 20px;/*圆角*/ padding: 20px; background-color: rgba(255,255,255,5); font-size: 20px; } .speech{ height: 55px; width: 100%; font-size: 18px; outline: none; border: none; background-color:#000; color: #fff; cursor: pointer;/*鼠标样式,小手*/ border-radius: 20px; } .speech:hover{/*hover伪类选择器 当鼠标滑过speech改变背景颜色*/ background-color: #ea4c89 } </style> </head> <body > <div> <textarea class="input_box" placeholder="请输入文字......"></textarea> <input class="speech" type="submit" value="立刻朗读"> </div> <script>/*JavaScript代码*/ function speeching(inputBox,speechBtn) { var inputBox = document.querySelector(inputBox), speechBtn = document.querySelector(speechBtn); var inputText = ''; speechBtn.onclick = function(){ var message = null;/*默认文本框为空*/ var text = inputBox.value;/*接收按钮得到的值*/ message = new SpeechSynthesisUtterance(text);/*传给message*/ window.speechSynthesis.speak(message);/*利用电脑本身应用读取输入内容*/ } } </script> <script> speeching('.input_box','.speech'); </script> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。