簡體   English   中英

帶有HTML5中“音頻”元素的JQuery

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM