单选按钮单击或检查 [英] radio button click or check

查看:101
本文介绍了单选按钮单击或检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hiiii,



i在一组中有3个单选按钮A,B,C

并且还有3个Div

i想要为每个单选按钮显示一个div



例如: -

当用户选择A - >苹果字出现

当用户选择B - >当用户选择C - >时,球词出现[删除Apple]

猫字出现[移除球和猫]



如下图所示,它有效但不是我想要的方式



如果用户在运行时更改了他的选择,它没有删除旧的div的答案

我该怎么办?


hiiii ,

i have 3 radio buttons A , B , C in one group
and have also 3 Div
i want to show a div for each radio button

for example :-
when user choose A --> apple word appeared
when user choose B --> ball word appeared [ remove Apple ]
when user choose C --> Cat word appeared [ remove ball and cat ]

as shown below , it works but not the way i want

if user change his choice during the running time , it didn't remove the old div 's answer
how can i do it ??

<head runat="server">
    <title></title>
    <script src="jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("div").hide();
            var myfunction = function (id, result) {
                $(id).click(function () {
                    $(result).show();
                });
            };

            myfunction('#radio1', '#divapple');
            myfunction('#radio2', '#divBall');
            myfunction('#radio3', '#divCat');
        });
        
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table>
        <tr>
            <td>
                <input type="radio" id="radio1" name="x" />A
                <input type="radio" id="radio2" name="x" />B
                <input type="radio" id="radio3" name="x" />C
                <br />
                <div id="divapple">
                    Apple
                </div>
                <div id="divBall">
                    Ball
                </div>
                <div id="divCat">
                    Cat
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

推荐答案

document )。ready( function (){
(document).ready(function () {


div)。hide();
var myfunction = function (id,result){
("div").hide(); var myfunction = function (id, result) {


(id).click( function (){
(id).click(function () {


这篇关于单选按钮单击或检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆