处理js中的单选按钮

时间:2015-06-22 21:28:33

标签: javascript

我用两页创建了这个计算器。第一页包含注册表单,第二页包含计算器

第一页的HTML:

QList<Msg>&            messages()      const       { return _messages; }

第二页的HTML:

<!DOCTYPE html>
<html>
<head>
    <title>js assigment 1 _ omar azzazy</title>
    <link rel="stylesheet" href="css/style.css"/>
</head>
<body>
    <div class="container">
        <h1>Registration form</h1>

        <form action="calc.html">
            First Name: <input type="text"/><br><br>
            Last Name: <input type="text"/><br>
            Gender: 
        <input id="m" type="radio" name="gender" value="male"/> Male <br>
     <input id="f" type="radio" name="gender" value="female"/>Female <br>
            <input type="submit" onclick="go()" value="Go to calculator">
        </form>
    </div>

    <script src="js/plugin.js"></script>
</body>

javascript代码:

<!DOCTYPE html>
<html>
<head>
    <title>js assigment 1 _ omar azzazy</title>
    <link rel="stylesheet" href="css/style.css"/>
</head>
<body>
    <div class="container">
        <h1>calculator</h1>

        <input id="operator1" type="number" value=""/>
        <select id="operatorx">
            <option value="0">+</option>
            <option value="1">-</option>
            <option value="2">x</option>
            <option value="3">/</option>
        </select>
        <input id="operator2" type="number" value=""/>
        <button onclick="calc()">=</button>
        <input id="result" type="text" value=""/>
    </div>

    <script src="js/plugin.js"></script>
</body>
</html>

如果用户在单选按钮中选择了“男性”,我需要页面和计算器按钮的颜色适合男士情绪。

如果用户选择“女性”,则页面和计算器按钮的颜色将适合女性情绪。

1 个答案:

答案 0 :(得分:0)

您需要首先检查使用document.getElementById("id").checked = true;

选择的内容

然后使用javascript的“style”元素添加样式,或按照此处的建议创建添加和删除:

Change an element's class with JavaScript

相关问题