2010-11-19 50 views
2

我想播放聲音onclick事件。我有代碼可以在Firefox和其他瀏覽器中播放聲音,但不能在Safari瀏覽器中播放。 以下是代碼。 Safari給我的錯誤,如"thissound.Play" [undefined ] is not a function在safari中使用javascript播放聲音

function EvalSound(soundobj) { 
    var thissound= eval("document."+soundobj); 
    thissound.Play(); 
} 

<embed src="namaste_london01(www.songs.pk).mp3" autostart=false width=0 height=0 name="sound1" 
enablejavascript="true"> 

<a href="#" onClick="EvalSound('sound1')"> Play </a> 

在此先感謝。

+2

你爲什麼使用'eval'?你可以簡單地使用'document ['sound1']。Play()'。 – jwueller 2010-11-19 10:46:31

回答

0

jQuery有一些很棒的音頻插件。這也意味着你可以擺脫令人討厭的onclick屬性,並保持腳本標記之間的所有JavaScript。

+0

您的JavaScript實際上不應該在'