function simpleSwap() { var the_image = prompt("change parrot or cheese",""); var the_image_name ="window.document."+ the_image; var the_image_object = eval(the_image_name); the_image_object.src ="ant.gif"; }
2.名称索引
function simpleSwap() { var the_image = prompt("change parrot or cheese",""); window.document.images[the_image].src ="ant.gif"; }