2

我的标记

而这个 JQuery 代码

每次我按播放时都会给我错误

<div class = "container">
    <legend><strong>Zedd - Spectrum</legend></h4>
    <div class = "art-item"><img src="uploads/arts/default.jpg"></div>
        <audio class = "audio-player" src = "uploads/tracks/02 So Far.mp3">
        </audio>

            <div class = "playerContainer">

                <ul id =  "playerControls" >
                    <li class = "play-bt"></li>
                    <li class = "pause-bt"></li>
                    <li><div class ="progressContainer"><!-- Progess bars container //-->
                        <div class ="progressbar"></div>
                    </div>
                    </li>

                </ul>
                <span class ="timecode">0:00</span>
            </div>
</div>


<div class = "container">
    <legend><strong>Zedd - Spectrum</legend></h4>
    <div class = "art-item"><img src="uploads/arts/default.jpg"></div>
        <audio class = "audio-player" src = "uploads/tracks/track3.mp3">
        </audio>

            <div class = "playerContainer">

                <ul id =  "playerControls" >
                    <li class = "play-bt"></li>
                    <li class = "pause-bt"></li>
                    <li><div class ="progressContainer"><!-- Progess bars container //-->
                        <div class ="progressbar"></div>
                    </div>
                    </li>

                </ul>
                <span class ="timecode">0:00</span>
            </div>
</div>

每次我单击 play-bt 时,它都会不断给我这个错误

Uncaught TypeError: Object #<Object> has no method 'play' 

音频标签不是有播放方法吗?

4

2 回答 2

6

jQuery.find()返回一个jQuery object,而不是 native HTMLAudioElement,所以你需要解开返回的值.find()

$artItem.find('audio')[0].play();
// or
$artItem.find('audio').get(0).play();
于 2012-08-08T12:45:10.687 回答
1

您在这里访问 jquery,而不是普通的 dom 标签所以尝试:

$artItem.find("audio")[0].play()
于 2012-08-08T12:44:53.800 回答