当前位置:网站首页>laravel-admin 用 原生JS实现声音提示,及自动播放
laravel-admin 用 原生JS实现声音提示,及自动播放
2022-06-26 10:04:00 【siner.li】
本内容是在laravel-admin HomeController.php 内书写的
html部分
<h3><span class='label' id="onejs">$data[0]
<audio id="sound" autoplay="autoplay"></audio>
</span></h3>
JS部分
<script >
var onejs = document.getElementById('onejs');
var sound = document.getElementById("sound");
setInterval(function () {
// '/' 后面跟请求路径, data 为请求参数
$.get("/",function(data){
if ((data > 0) && (onejs.innerHTML < data)){
sound.src="/tip.mp3";
}
onejs.innerHTML = data;
});
},5000);
</script>
自动播放音频
必须要有页面的交互动作, 对于谷歌浏览器来说
html部分
<span class='label' id="onejs">$data[0]
<audio id="sound" muted autoplay src="/tip.mp3"></audio>
</span>
js部分
var onejs = document.getElementById('onejs');
var sound = document.getElementById("sound");
setInterval(function () {
$.get("/help",function(data){
if ((data > 0) && (onejs.innerHTML < data)){
sound.muted=false
sound.play()
}
onejs.innerHTML = data;
});
},5000);
边栏推荐
猜你喜欢

Vscode environment setup: synchronous configuration

JS take the date of the previous month 【 pit filling 】

Idea remote debugger

Fabric.js 上划线、中划线(删除线)、下划线

ACK攻击是什么意思?ACK攻击怎么防御?

Origin of b+ tree index

Docker中实现MySQL主从复制

Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training

栖霞市住建局和消防救援大队开展消防安全培训

Grain Mall - distributed Foundation
随机推荐
Bit operation n & (n-1), leetcode231, interview question 05.06
Redis中执行Lua脚本
[echart] II. User manual and configuration item reading notes
Function run time
Vscode environment setup: synchronous configuration
nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
The difference between NPM and yarn
Expand and collapse too high div
Redis knowledge mind map
你好!正向代理!
Will updating a large amount of data in Oracle cause the undo space to explode
[online simulation] Arduino uno PWM controls the speed of DC motor
appliedzkp zkevm(8)中的Plookup Table
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
即构「畅直播」上线!提供全链路升级的一站式直播服务
Using baijiafan to automatically generate API calls: progress in JS (II)
服务器单、双向可调一键互信脚本!
Installer MySQL sous Linux [détails]
MySQL 12th job - Application of stored procedure
The sixth MySQL job - query data - multiple conditions