Javascript Soundmanager:未定义MySound soundManager.url='swf/'; soundManager.createSound({ id:'我的声音', 网址:'http://localhost/htmlshooter/mp3/gun.mp3', 自动加载:对, 自动播放:对, 数量:100 }); 函数placeimage(){ 变量t=$(''); $('#div')。追加(t); t、 css('left',Math.floor(Math.random()*(800-t.width())); t、 css('top',Math.floor(Math.random()*(300-t.height())); 设置超时(placeimage,2000); } placeimage(); 函数doclickimg(imgid){ doclickdiv(); $('#'+imgid).remove(); //+1分 } 函数doclickdiv(){ mySound.play(); //-1颗子弹 }
现在,当我单击我的div时,图像不会消失,它说没有定义doclickdiv()中MySound.play中的MySoundJavascript Soundmanager:未定义MySound soundManager.url='swf/'; soundManager.createSound({ id:'我的声音', 网址:'http://localhost/htmlshooter/mp3/gun.mp3', 自动加载:对, 自动播放:对, 数量:100 }); 函数placeimage(){ 变量t=$(''); $('#div')。追加(t); t、 css('left',Math.floor(Math.random()*(800-t.width())); t、 css('top',Math.floor(Math.random()*(300-t.height())); 设置超时(placeimage,2000); } placeimage(); 函数doclickimg(imgid){ doclickdiv(); $('#'+imgid).remove(); //+1分 } 函数doclickdiv(){ mySound.play(); //-1颗子弹 },javascript,jquery,soundmanager2,Javascript,Jquery,Soundmanager2,现在,当我单击我的div时,图像不会消失,它说没有定义doclickdiv()中MySound.play中的MySound 请帮帮我!为什么这不起作用 您收到此错误是因为myound尚未定义对象。你可能会有更好的运气与 soundManager.url = 'swf/'; soundManager.createSound({ id: 'mySound', url: 'http://l
请帮帮我!为什么这不起作用 您收到此错误是因为
myound
尚未定义对象。你可能会有更好的运气与
soundManager.url = 'swf/';
soundManager.createSound({
id: 'mySound',
url: 'http://localhost/htmlshooter/mp3/gun.mp3',
autoLoad: true,
autoPlay: true,
volume: 100
});
function placeimage(){
var t = $('<img src="img/php/target.png" alt="image" id="' + Math.floor(Math.random()*55) + '" onclick="doclickimg(this.id);">');
$('#div').append(t);
t.css('left', Math.floor(Math.random()*(800 - t.width())));
t.css('top', Math.floor(Math.random()*(300 - t.height())));
setTimeout(placeimage, 2000);
}
placeimage();
function doclickimg(imgid){
doclickdiv();
$('#'+imgid).remove();
// +1 score
}
function doclickdiv() {
mySound.play();
// -1 bullet
}
或者
未定义mySound。您可能想要更改:
function doclickdiv() {
soundManager.getSoundById('mySound').play();
// -1 bullet
}
到
function doclickdiv() {
soundManager.getSoundById('mySound').play();
// -1 bullet
}
soundManager.createSound({
id: 'mySound',
url: 'http://localhost/htmlshooter/mp3/gun.mp3',
autoLoad: true,
autoPlay: true,
volume: 100
});
var mySound = soundManager.createSound({
id: 'mySound',
url: 'http://localhost/htmlshooter/mp3/gun.mp3',
autoLoad: true,
autoPlay: true,
volume: 100
});