js布局实现单选按钮控件
人气:0主要是对最近学习的知识做练习,可以巩固提高!
效果如下图:
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>单选控件</title> <style type="text/css"> .radioD{ width: 300px; height: 300px; background: url(field.jpg) no-repeat; } .radioD li{ font-size: 18px; font-family: Arial; list-style: none; } .leftU{ float: left; } .rightU{ float: right; margin-right: 80px; } </style> <script type="text/javascript"> window.onload = function(){ var aLi = document.getElementsByTagName('li'); var aInput = document.getElementsByTagName('input'); var i = 0; var btn = document.getElementById('foodBtn'); btn.onclick = function(){ for(i=0;i<aInput.length;i++) { if(aInput[i].checked == true){ alert(aInput[i].value); } } } } </script> </head> <body> <div class="radioD"> <ul class="leftU"> <li><input type="radio" name="food" value="面条1">面条1</li> <li><input type="radio" name="food" value="馒头1">馒头1</li> <li><input type="radio" name="food" value="烧饼1">烧饼1</li> <li><input type="radio" name="food" value="窝头1">窝头1</li> </ul> <ul class="rightU"> <li><input type="radio" name="food" value="面条2">面条2</li> <li><input type="radio" name="food" value="馒头2">馒头2</li> <li><input type="radio" name="food" value="烧饼2">烧饼2</li> <li><input type="radio" name="food" value="窝头2">窝头2</li> </ul> <button id="foodBtn">我的食物</button> </div> </body> </html>
您可能感兴趣的文章:
加载全部内容