在javascript中 怎样调用函数 转换不同的背景图片
发布网友
发布时间:2024-10-12 01:53
我来回答
共1个回答
热心网友
时间:2024-12-14 01:37
<!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=gbk" />
<meta name="Keywords" content=""/>
<meta name="Description" content=""/>
<title>背景图片变换效果</title>
<script type="text/javascript">
function chgBgImg(id, src){
document.getElementById(id).style.backgroundImage = "url(" + src + ")";
}
</script>
<style type="text/css">
#img{width:110px;height:82px;margin:50px auto;border:4px solid #ccc;}
</style>
</head>
<body>
<div id="img"></div>
<input type="button" onclick="chgBgImg('img', 'http://media2.ihompy.com/200908/23/11011059381_12510156189tmq.jpg');" value="第1张"/>
<input type="button" onclick="chgBgImg('img', 'http://media2.ihompy.com/200908/23/11011059381_1251015601jaa5.jpg');" value="第2张"/>
<input type="button" onclick="chgBgImg('img', 'http://media2.ihompy.com/200908/23/11011059381_1251015565odgs.jpg');" value="第3张"/>
</body>
</html>