如何让 JavaScript 发出哔哔声? [英] How do I make JavaScript beep?
本文介绍了如何让 JavaScript 发出哔哔声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的网页在用户超过我的 <textarea>
的最大字符限制时发出哔哔声.
I want my web page to beep whenever a user exceeds the maximum character limit of my <textarea>
.
推荐答案
无法直接在 JavaScript 中执行.您需要在 HTML 中嵌入一个简短的 WAV 文件,然后通过代码播放.
It's not possible to do directly in JavaScript. You'll need to embed a short WAV file in the HTML, and then play that via code.
一个例子:
<script>
function PlaySound(soundObj) {
var sound = document.getElementById(soundObj);
sound.Play();
}
</script>
<embed src="success.wav" autostart="false" width="0" height="0" id="sound1"
enablejavascript="true">
然后您可以从 JavaScript 代码中调用它:
You would then call it from JavaScript code as such:
PlaySound("sound1");
这应该完全符合您的要求 - 您只需要自己查找/创建哔声,这应该是微不足道的.
This should do exactly what you want - you'll just need to find/create the beep sound yourself, which should be trivial.
这篇关于如何让 JavaScript 发出哔哔声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文