在单选按钮上更改jquery中按钮的颜色

时间:2022-11-20 14:17:02

Q1 A O B O C O D O

Q1 A O B O C O D O.

 1   2

'-->When i select any radio button from Q1 then color of button '1' and button '2' must change shwon in image...

' - >当我从Q1中选择任何单选按钮时,按钮'1'和按钮'2'的颜色必须在图像中改变shwon ...

在单选按钮上更改jquery中按钮的颜色

<!DOCTYPE html>

<html>
    <head>
        <style>
            .ButtonClicked {
                background-color:red;
            }
        </style>
        <script src="jquery-2.1.3.js"></script>
        <script>
            $(document).ready(function () {
                $(document).on('change', 'input[name="groupA"]:radio', function () {
                    // alert($(this).val());
                    $(#btn1).addClass('ButtonClicked');
                });
            });
        </script>
    </head>
    <body>
        Q1 <input type="radio" id="radio1a" name="groupA" value="1">
        <input type="radio" id="radio2a" name="groupA" value="2">
        <input type="radio" id="radio3a" name="groupA" value="3">
        <input type="radio" id="radio4a" name="groupA" value="4">
        <br>
        <button id="btn1">1</button>
        <button id="btn2">2</button>
    </body>
</html>

when try above code button 1 color is not changed don't know whats the mistake i done..

当尝试上面的代码按钮1颜色没有改变不知道我做的错误是什么..

EDIT: i forgot quotes in $(#btn1) anyway thanks..

编辑:我忘了$(#btn1)中的引号,谢谢..

1 个解决方案

#1


1  

you forgot the quotes try this

你忘记了引号试试这个

 $("#btn1").addClass('ButtonClicked');

#1


1  

you forgot the quotes try this

你忘记了引号试试这个

 $("#btn1").addClass('ButtonClicked');