Javascript 无法在本地主机中播放音频文件
这是我在localhost中播放音频文件的代码,由于无法打开位置而出错;您可能没有打开该文件的权限。请提前帮我一下Javascript 无法在本地主机中播放音频文件,javascript,Javascript,这是我在localhost中播放音频文件的代码,由于无法打开位置而出错;您可能没有打开该文件的权限。请提前帮我一下 <!DOCTYPE html> <html> <head> <center> <script language="JavaScript" type="text/javascript"> function getPath() { playId.
<!DOCTYPE html>
<html>
<head>
<center>
<script language="JavaScript" type="text/javascript">
function getPath() {
playId.src = "/root/Desktop/103.mp3";
}
</script>
</center>
</head>
<body>
<input type="submit" value="PLAY PATH" onclick="getPath()" />
<embed height="50" width="100" id="playId">
</body>
</html>
未定义playId。您需要找到元素,然后设置属性
document.getElementById('playId').src = "/root/Desktop/103.mp3";
此外,如果尚未设置,则可能需要将其设置为本地文件://URL。函数getPath{playId.src=/root/Desktop/103.mp3;}欢迎使用堆栈溢出!要改进您的问题,请使用问题下的编辑链接,而不是发表评论。我已将您的HTML复制到问题中。