(编辑:jimmy 日期: 2024/11/16 浏览:2)
本文实例为大家分享了javascript布局实现单选按钮控件的具体代码,供大家参考,具体内容如下
主要是对最近学习的知识做练习,可以巩固提高!
效果如下图:
代码如下:
<!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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。