下面的js对象会在实例化后生成指定的图片。我想要的是让图像sayQuote
在浏览器中单击时执行。建议?
function CharType()
{
this.charImage = function(whichImage)
{
var image = document.createElement("img");
image.src = "characters/"+whichImage;
document.body.appendChild(image);
}
function sayQuote()
{
alert(getQuote());
}
// this.onclick = sayQuote(); // nope, that doesn't do it!
}
实例化:
var stickfigure = new CharType();
stickfigure.charImage("stickfigure.png");