jquery手机播放声音onclick



我正在用HTML5和jQuery mobile为智能手机开发一个网络应用程序,我的页面中有5个按钮(5个选项),所以我想为每个按钮播放不同的嘟嘟声。我怎么能这么做!!

HTML中的某个位置:

<button id="button1Id">Button 1</button>

将监听器设置为按钮,例如:

$("#button1Id").click( function (event) {
    //Prevent the default button action (I suppose the default click sound is,
    //if it exists on thedevice, is removed by this)
    e.preventDefault(event);
    //TODO: Insert code for audio file playback here
    $.mobile.changePage("destination.html");
}

然后,您可以对所有不同的按钮重复此代码。我没有包括音频播放的代码,因为问题中不清楚你是否需要帮助。有几种方法可以实现,例如,您可以使用:https://developer.mozilla.org/en-US/docs/HTML/Element/Audio

最新更新