最近在做一个需要预览数据库图片的例子,反复地搞了好几次,总是感觉不舒服,先是用新窗口看图片,结果发现用层来预览要更好些,不过这只是一个最最简单的示例,因为页面是frame结果显示老是不能居中,为了留作备用就发了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用div预览图片Javascript作事件监听的例子</title>
</head>
<body>
<div id="s1">预览图片</div>
<div id="show" style="visibility:hidden;" ><img src="my.jpg" alt="双击关闭"></div>
<script language="javascript" type="text/javascript" >
var f1=document.getElementById("show");
var openevent=function(){
f1.style.visibility = "visible"; }
var closeevent=function(){
f1.style.visibility = "hidden";}
var p1=document.getElementById("s1");
p1.attachEvent("onclick",openevent);
f1.attachEvent("ondblclick",closeevent);
</script>
</body>
</html>