Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

audio - Cross-platform, cross-browser way to play sound using jQuery 1.4?

I'm trying to get jQuery to play a sound on element hover/click. (It's like a flash website without flash)

I've tried the methods recommended in Cross-platform, cross-browser way to play sound from Javascript?, the jQuery Sound plugin and a couple of other tutorials without any success. I'm assuming this is because they haven't been updated since 2008.

Does anyone have any recommendations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Don't need any of those. The HTML tag, combined with JavaScript, will do the trick.

<audio id="soundHandle" style="display: none;"></audio>
<script>
  soundHandle = document.getElementById('soundHandle');
  soundHandle.src = '/blah/blah.mp3';
  soundHandle.play();
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...