这个<script>放到<body>最后试试- <script>
- (function () {
- var audioPlaying = null;
- function audio_ended(e) {
- var nodeNext = e.target.nextElementSibling;
- if (nodeNext && nodeNext.nodeName.toLowerCase() == 'audio') {
- nodeNext.play();
- } else {
- audioPlaying = null;
- }
- }
- function audio_play(e) {
- audioPlaying = e.target;
- }
- function xpr_click(e) {
- if (audioPlaying && !audioPlaying.paused) {
- audioPlaying.pause();
- }
- e.currentTarget.getElementsByTagName('audio')[0].play();
- }
- var xprlist = document.getElementsByTagName('x-pr');
- for (var i = 0; i < xprlist.length; i++) {
- var xpr = xprlist[i];
- var soundlist = xpr.getElementsByTagName('a');
- for (var j = 0; j < soundlist.length; j++) {
- var nodeAudio = document.createElement('audio');
- nodeAudio.setAttribute('src', soundlist[j].getAttribute('href').replace(/^sound:\/\//i, ''));
- nodeAudio.addEventListener('play', audio_play, false);
- nodeAudio.addEventListener('ended', audio_ended, false);
- xpr.appendChild(nodeAudio);
- }
- xpr.addEventListener('click', xpr_click, false);
- }
- })();
- </script>
复制代码
|