首页前端开发JavaScriptHTML如何实现RadioButton单选按钮

HTML如何实现RadioButton单选按钮

时间2024-01-28 23:59:03发布访客分类JavaScript浏览540
导读:收集整理的这篇文章主要介绍了HTML如何实现RadioButton单选按钮,觉得挺不错的,现在分享给大家,也给大家做个参考。用HTML来实现RadioButton,需要使用input标签,其中tyPE指定为radio,接下来的文章我们就来说...
收集整理的这篇文章主要介绍了HTML如何实现RadioButton单选按钮,觉得挺不错的,现在分享给大家,也给大家做个参考。用HTML来实现RadioButton,需要使用input标签,其中tyPE指定为radio,接下来的文章我们就来说一说详细的内容。

我们先来看input标签的格式

input id="(id)" name="(组名称)" type="radio">
    /input>
    

注:对于需要选中检索的值,可以利用表单的提交或使用JavaScript获取。

我们来看具体的示例

代码如下

!DOCTYPE html>
    html>
    head>
    meta http-equiv="Content-type" content="text/html;
     charset=utf-8"/>
      tITle>
    /title>
    /head>
    body>
      form name="form1" action="">
        input id="Radio1" name="RadioGroup1" type="radio" />
    label for="Radio1">
    单选按钮 元素1/label>
    br/>
        input id="Radio2" name="RadioGroup1" type="radio" />
    label for="Radio2">
    单选按钮 元素2/label>
    br />
        input id="Radio3" name="RadioGroup1" type="radio" />
    label for="Radio3">
    单选按钮 元素3/label>
    br />
      /form>
      div id="output">
    /div>
    /body>
    /html>
    

运行结果

使用Web浏览器打开上述HTML文件时,将显示如下所示的效果。

单击以更改单选按钮的选中状态

在多个组中使用RadioButton时

代码如下

!DOCTYPE html>
    html>
    head>
    meta http-equiv="Content-Type" content="text/html;
     charset=utf-8"/>
        title>
    /title>
    /head>
    body>
      form name="form1" action="">
        div style="margin:16px;
    border:dotted 1px #202020;
    ">
          input id="Radio1" name="group01" type="radio" />
    label for="Radio1">
    单选项目1/label>
    br />
          input id="Radio2" name="group01" type="radio" />
    label for="Radio2">
    单选项目2/label>
    br />
          input id="Radio3" name="group01" type="radio" />
    label for="Radio3">
    单选项目3/label>
    br />
        /div>
        div id="output1">
    /div>
        div style="margin:16px;
    border:dotted 1px #202020;
    ">
          input id="Radio4" name="group02" type="radio" />
    label for="Radio4">
    单选项目4/label>
    br />
          input id="Radio5" name="group02" type="radio" />
    label for="Radio5">
    单选项目5/label>
    br />
          input id="Radio6" name="group02" type="radio" />
    label for="Radio6">
    单选项目6/label>
    br />
        /div>
        div id="output2">
    /div>
      /form>
    /body>
    /html>
    

说明:

要将单选按钮分成多个组,请将每个组的name属性设置为不同名称。在上面的例子中,Radio 1,Radio 2,Radio 3的name属性是group 1。Radio 4,Radio 5,Radio 6的name属性是第2组。

运行结果

使用Web浏览器打开上述HTML文件时,将显示如下所示的效果。

每组都是分开的,单选按钮的选择是独立的。

以上就是HTML如何实现RadioButton单选按钮的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

上一篇: 超链接怎么做下一篇:如何在HTML上插入图片猜你在找的JavaScript相关文章 html font标签如何设置字体大小?html font标签属性用法介绍2022-05-16vue3+TypeScript+vue-router的使用方法2022-04-16vue3获取当前路由地址2022-04-16如何利用React实现图片识别App2022-04-16JavaScript展开运算符和剩余运算符的区别详解2022-04-16微信小程序中使用vant框架的具体步骤2022-04-16Vue elementUI表单嵌套表格并对每行进行校验详解2022-04-16如何利用Typescript封装本地存储2022-04-16微信小程序中wxs文件的一些妙用分享2022-04-16JavaScript的Set数据结构详解2022-04-16 其他相关热搜词更多phpjavapython程序员loadpost-format-gallery

若转载请注明出处: HTML如何实现RadioButton单选按钮
本文地址: https://pptw.com/jishu/590331.html
html字体有哪些 figure标签是什么?什么时候用?

游客 回复需填写必要信息