使用单选按钮中的 value 属性

<input type="radio" name="brower">  必须一起存在,不然单选框有误。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        function F(x)
        {
            document.getElementById("answer").value=x;
        }
    </script>
</head>
<body>
    <p>您最喜欢哪款浏览器</p>
    <form>
        <input type="radio" name="brower" onclick="F(this.value)" value="Internet Explorer">Internet Explorer <br>
        <input type="radio" name="brower" onclick="F(this.value)" value="Firefox">Firefox <br>
        <input type="radio" name="brower" onclick="F(this.value)" value="Netscape">Netscape <br>
        <input type="radio" name="brower" onclick="F(this.value)" value="Opera">Opera <br>
        您喜欢的浏览器是:<input type="text" id="answer" size="20">
    </form>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_31741481/article/details/87875418