아래의 js 객체는 인스턴스 생성 후 지정된 이미지를 생성합니다. 브라우저에서 이미지를 클릭하여 sayQuote
을 실행하면됩니다. 제안?js 객체에서 'onclickable'이미지 만들기
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");
당신이하고자하는 일에 대한 더 큰 그림을 보여주고 싶을 수도 있습니다. –
거의 이것뿐입니다. getQuote 함수는 따옴표를 전달합니다. 위의 인스턴스를 추가했습니다. –