[英]JQuery with “audio” element in HTML5
我是JQuery的新手,这是一个基本问题,我不理解为什么以下代码不起作用。 请帮我弄清楚。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js">
</script>
<script>
function test()
{
var audios=$("#audio1");
alert(audios.volume); //This line does not work, it returns "undefined"
audios.volume=0.5; //This line does not work
// audios.hide(); - This works fine
}
</script>
<title>This is a test</title>
</head>
<body>
<input type="button" value="Test" onclick="test()">
<audio id="audio1" controls autoplay>
<source src="http://zz.qz828.net/06/three.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
不知道为什么这两行不起作用:
alert(audios.volume); //This line does not work
audios.volume=0.5; //This line does not work
谢谢!
您需要将volume属性设置为dom元素, $("#audio1")
返回一个不具有volume
属性的jQuery对象。
因此,您需要从jQuery对象访问dom元素,然后设置属性或使用.prop()设置属性值
audios[0].volume=0.5;
//or audios.prop('volume', 0.5);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.