javascript - 即使您在输入字段中有多个字母/数字(rfid 代码),如何让它只说一次?
问题描述
每当我点击有 10 个字符代码的 RFID 时,代码都会循环 10 次,我怎样才能让它只说一次然后取消下一个?
$(function(){
if ('speechSynthesis' in window) {
speechSynthesis.onvoiceschanged = function() {
var $voicelist = $('#voices');
if($voicelist.find('#voices').length == 0) {
speechSynthesis.getVoices().forEach(function(voice, index) {
var $option = $('#voices')
.val(index)
.html(voice.name + (voice.default ? ' (default)' :''));
$voicelist.append($option);
});
}
}
$('#rfid').keypress(function(){
var text = document.getElementById("res").innerHTML;
var msg = new SpeechSynthesisUtterance();
var voices = $('#voices');
msg.voice = voices[$('#voices').val()];
msg.rate = 10 / 10;
msg.pitch = 1;
msg.text = text;
speechSynthesis.speak(msg);
})
}
});
解决方案
推荐阅读
- jquery - 项目从 Vue-cli 2.0 迁移到 3.0 后 Owl.carousel 无法工作
- python - 根据键名搜索和更新嵌套字典
- javascript - 在 Google 地图上启用用户位置选择
- java - java.lang.IllegalStateException:连接池关闭。如何处理多线程应用程序中的连接池异常?
- bundle - 如何在 shopware 6 后端的自定义包中上传图像?
- ios - Xcode iOS 自动代码签名与 com.apple.developer.passkit.pass-presentation-suppression
- vbscript - VBS 检查互联网并延迟脚本直到准备好
- javascript - 一次旋转完成后如何在jQuery中停止动画?
- spring - 将请求方法与 Kotlin DSL 匹配以实现 Spring Security
- sql-server - SQL Server 如何决定使用哪个“where”语句?