JavaScript代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=gb2312" /> <title>用JS实现的radio图片选择按钮效果</title> <style> .lanrentuku img{border:1px solid #008800;} </style> </head> <body> <script> function myFun(sId) { var oImg = document.getElementsByTagName( 'img' ); for ( var i = 0; i < oImg.length; i++) { if (oImg[i].id == sId) { oImg[i].previousSibling.previousSibling.checked = true ; oImg[i].style.border = '1px solid #FF6600' ; } else { oImg[i].style.border = '1px solid #008800' ; } } } </script> <div class= "lanrentuku" >
<input type= "radio" value= "lanrentuku" id= "111" name= "aaa" style= "display:none" > "aa" src= "http://www.lanrentuku.com/down/js/images/12625207690.gif onclick= "myFun(this.id)" >
<input type= "radio" value= "lanrentuku" id= "222" name= "aaa" style= "display:none" > "bb" src= "http://www.lanrentuku.com/down/js/images/12625207691.gif" onclick= "myFun(this.id)" >
<input type= "radio" value= "lanrentuku" id= "333" name= "aaa" style= "display:none" > "cc" src= "http://www.lanrentuku.com/down/js/images/12625207692.gif" onclick= "myFun(this.id)" > </div> <p>用JS实现的radio图片选择按钮效果。</p> <p>注意:input后面的空格。</p> |