function aa()
{
alert("aaaaa");
}
function test()
{
document.write('<img src="image/009.jpg" width=110 height=110 border="1" onclick="aa();">');
}
这段代码触发了test函数后,能正常显示009.jpg这张图片,但是这图片的onclick事件失效,点击图片之后不能触发到aa函数,不知道是什么原因。请教各位高手.
{
alert("aaaaa");
}
function test()
{
document.write('<img src="image/009.jpg" width=110 height=110 border="1" onclick="aa();">');
}
这段代码触发了test函数后,能正常显示009.jpg这张图片,但是这图片的onclick事件失效,点击图片之后不能触发到aa函数,不知道是什么原因。请教各位高手.
你调用test()以后,看到图片了。右键查看一下页面源代码,看看除了这张图片以外,其他的东西还在不在
{
alert("aaaaa");
}
function test()
{
document.write('<img src="images/0.gif" width=110 height=110 border="1" onclick="aa();">');
}test();可以触发啊
function test()
{
document.getElementById('theforever_csdn').innerHTML='<img src="image/009.jpg" width=110 height=110 border="1" onclick="aa();">';
}
然后在BODY中增加一行
<div id="theforever_csdn">图片将要显示在这里</div>
你应该把图片的html输出到一个标签,用innerHTML取代document.write
或者创建html对象,用appendChild方式加载到页面:
function aa()
{
alert("aaaaa");
}
function test()
{
var img1=document.createElement("img");
img1.src="image/009.jpg";
img1.style.width='110px';
img1.style.height='110px';
img1.onclick=aa;
document.body.appendChild(img1);
}
<html>
<head>
<title> 测试 </title>
<script type="text/javascript">
function aa(){
alert("aaaaa");
};
function test(){
document.write('<img src="image/009.jpg" width=110 height=110 border="1" onclick="aa();">');
};
test();
</script>
</head>
<body>
</body>
</html>
可是摆在script里调用,却安然无恙。
这不科学啊,求解释。
我也是。印象中,我从未用过document.write