首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

单选框图片显示解决方案

2012-02-08 
单选框图片显示有三个单选框~~每个对应一张图片~~~选中一个单选框后~~~会把对应的图片显示在上面的 div

单选框图片显示
有三个单选框~~每个对应一张图片~~~
选中一个单选框后~~~会把对应的图片显示在上面的 <div> 层中
的js怎么写
<div>
</div>
<hr>
<form   name=f1   id=f1>
<table   border= "1 "   cellpadding= "0 "   cellspacing= "1 "   bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input   type= "radio "   value= "07 "   name= "webmodel "   /> NO.01 </td>
</tr>
<tr>
<td   bgcolor= "#ffffff "> <a   href= "# "> <img   src= "1.jpg "   width= "140 "   height= "200 "   border= "0 "   /> </a> </td>
</tr>
</tbody>
</table> </td>
<td> <table   border= "1 "   cellpadding= "0 "   cellspacing= "1 "   bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input   type= "radio "   value= "07 "   name= "webmodel "   /> NO.02 </td>
</tr>
<tr>
<td   bgcolor= "#ffffff "> <a   href= "# "> <img   src= "2.jpg "   width= "140 "   height= "200 "   border= "0 "   /> </a> </td>
</tr>
</tbody>
</table> </td>
<td> <table   border= "1 "   cellpadding= "0 "   cellspacing= "1 "   bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input   type= "radio "   value= "07 "   name= "webmodel "   /> NO.03 </td>
</tr>
<tr>
<td   bgcolor= "#ffffff "> <a   href= "# "> <img   src= "3.jpg "   width= "140 "   height= "200 "   border= "0 "   /> </a> </td>
</tr>
</tbody>
</table>
</form>

[解决办法]
<html>
<style>
</style>
<script>
function showPic(picUrl)
{
document.getElementById( "dv ").style.backgroundImage = "url( "+picUrl+ ") ";
document.getElementById( "dv ").style.width=140;
document.getElementById( "dv ").style.height=200;
}
</script>
<body>
<div id=dv>
</div>
<hr>
<form name=f1 id=f1>
<table border= "1 " cellpadding= "0 " cellspacing= "1 " bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input type= "radio " value= "07 " name= "webmodel " onclick= "showPic( '1.jpg ') "/> NO.01 </td>
</tr>
<tr>
<td bgcolor= "#ffffff "> <a href= "# "> <img src= "1.jpg " width= "140 " height= "200 " border= "0 " /> </a> </td>
</tr>
</tbody>
</table> </td>
<td> <table border= "1 " cellpadding= "0 " cellspacing= "1 " bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input type= "radio " value= "07 " name= "webmodel " onclick= "showPic( '2.jpg ') "/> NO.02 </td>


</tr>
<tr>
<td bgcolor= "#ffffff "> <a href= "# "> <img src= "2.jpg " width= "140 " height= "200 " border= "0 " /> </a> </td>
</tr>
</tbody>
</table> </td>
<td> <table border= "1 " cellpadding= "0 " cellspacing= "1 " bordercolor= "#CCCCCC ">
<tbody>
<tr>
<td> <input type= "radio " value= "07 " name= "webmodel " onclick= "showPic( '3.jpg ') "/> NO.03 </td>
</tr>
<tr>
<td bgcolor= "#ffffff "> <a href= "# "> <img src= "3.jpg " width= "140 " height= "200 " border= "0 " /> </a> </td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
[解决办法]
<div id= "d "> </div>
<img id= "img1 " src= "1.jpg " height= "50 " width= "50 "> <input type= "radio " for= "img1 " onclick= "f(this) ">
<img id= "img2 " src= "2.jpg " height= "50 " width= "50 "> <input type= "radio " for= "img2 " onclick= "f(this) ">
<img id= "img3 " src= "3.jpg " height= "50 " width= "50 "> <input type= "radio " for= "img3 " onclick= "f(this) ">
<script>
o = document.getElementById( "d ");
function f(obj)
{
o.innerHTML = document.getElementById(obj.getAttribute( "for ")).outerHTML;
}
</script>

热点排行