Home >Web Front-end >JS Tutorial >Implementation case of JavaScript alarm sound effect

Implementation case of JavaScript alarm sound effect

黄舟
黄舟Original
2017-10-28 09:26:162915browse

Prototype diagram:

## Project requirements :

After receiving the alarm, the server will push the message to the front desk (through the effect of front-end real-time message prompt-websocket long polling). After receiving the message, the front desk needs to issue an alarm sound to remind the user.

Principle:

It’s very simple. You can use the b97864c2e0ef2353a16c4d64c7734e92 tag in HTML5. Select an alarm section on the official website of the ringtone. The

audio can be placed in the code.

Code snippet:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<audio autoplay="autoplay" id="auto" src=""></audio>
<input type="button" value="点击播放" onclick="playSound(&#39;http://data.huiyi8.com/2017/gha/03/17/1702.mp3&#39;)">
</body>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
 $(function(){
 function playSound(src) {
 var auto = $("#auto");
 auto.attr("src",src);
 }
 })

</script>
</html>
</script>
</html>

Summary

The above is the detailed content of Implementation case of JavaScript alarm sound effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn