【问题标题】:On Clicking Radio Button image should change单击单选按钮图像应更改
【发布时间】:2012-07-07 07:23:43
【问题描述】:

我有 3 个单选按钮,单击第一个按钮时应该调用一个图像。单击第二个按钮时,第一个图像应该消失,单击 3 第二个应该消失。我想用jquery来做。请帮帮我

【问题讨论】:

  • @SanketKotak,这个问题很差。您应该提供更多细节、一些代码或一些个人努力的暗示。

标签: jquery html phpmyadmin


【解决方案1】:

你可以在demo看到代码示例

这里是示例代码。 但是我同意每个人的观点,您应该发布一些示例代码来表明您正在做一些思考!

div{
height:50px;
    width:50px;
}
.yellow{
background-color:yellow
}
.green{
background-color:green;
}
.blue{
background-color:blue;
}
.red{
background-color:red;
}
​
<ul>
    <li><input type='radio' id='1' name='change'><label>red</label></li>
    <li><input type='radio' id='2' name='change'><label>blue</label></li>
    <li><input type='radio' id='3' name='change'><label>green</label></li>

</ul>

<div id='show' class='yellow'></div>

$(document).ready(function(){
    $('ul>li>input').change(function(index){
        console.log($(this));
        var id = $(this).attr('id');
        console.log(id);
        var cssClass = 'yellow';
        switch(id)
        {
            case '1':
                cssClass = 'red';
                break;
            case '2':
                cssClass = 'blue';
                break;
            case '3':
                cssClass = 'green';
                break;
        }
        console.log(cssClass);
        $('#show').removeClass().addClass(cssClass);
    });
});​

【讨论】:

    猜你喜欢
    • 2017-01-21
    • 2015-05-09
    • 2013-11-05
    • 1970-01-01
    • 2011-12-14
    • 2012-01-21
    • 2014-06-03
    • 1970-01-01
    相关资源
    最近更新 更多