zoukankan      html  css  js  c++  java
  • 获得Radio选中的后面文本框的值

    例如:

    选中的radio的值在button中显示

    代码如下:

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript">
    
            window.onload = function () {
                document.getElementById("btn").onclick = function () {
                    var phone = ""
                    var rdos = document.getElementsByName("rdo");
                    for (var i = 0; i < rdo.length; i++) {
                        if (rdos[i].checked) {
                            phone = document.getElementById(rdos[i].id + "_demo").value;
                            document.getElementById("btn").value = phone;
                        }
                    }
                }
            }
        </script>
    </head>
    <body>
        移动:
        <input type="radio" name="rdo" id="mobile" />
        <input type="text" name="name" id="mobile_demo" />
        固话: 
        <input type="radio" name="rdo" id="tel" />
        <input type="text" name="name" id="tel_demo" />
        <input type="button" name="name" value="您选择的号码是?" id="btn"/>
        </body>
    </html>

    值得注意的是radio的值和其后文本框的值命名有一定关系。这样可以通过选中的radio的值得到其后文本框的值。

  • 相关阅读:
    NKOJ P3051浇花
    Linux-Shell脚本编程-学习-2-Linux基本命令
    Linux-Shell脚本编程-学习-1-Linux基本命令
    Ubuntu下使用Git_6
    Ubuntu下使用Git_5
    电脑优化,提速
    Ubuntu下使用Git_4
    Ubuntu下使用Git_3
    Ubuntu下使用Git_2
    Ubuntu下使用Git_1
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3225447.html
Copyright © 2011-2022 走看看