简体   繁体   English

如何在单选按钮中更改样式

[英]How to change style in the radio button

I make an content changer with jquery, when you select an other radio button the content change, this is alright! 我使用jquery进行内容更改,当您选择另一个单选按钮时,内容更改就可以了! But i have tried change the radio title style when you make the change. 但是当您进行更改时,我尝试过更改广播标题的样式。 but i'm not getting it 但我不明白

DEMO 演示

Another thing. 另一件事。 When you change the content, the height of the box change too. 更改内容时,盒子的高度也会改变。 I have tried make a fluid motion using the property transition, but don't work =/ 我尝试使用属性转换进行流畅的运动,但是不起作用= /

Can anyone help me? 谁能帮我? Thank you in advance and have a merry christmas 预先谢谢你,祝圣诞快乐

               <form class="my-form-radio">
                    <input data-id="#form-show-item-1" type="radio" name="name" checked /><span class="active"> De Aeroporto para Bairro</span>
                    <input data-id="#form-show-item-2" type="radio" name="name" /><span> De Bairro para Aeroporto</span>
                    <input data-id="#form-show-item-3" type="radio" name="name" /><span> Ida e Volta </span>
                </form>

try something like this, FIDDLE 试试这样, FIDDLE

$('.my-form-radio input').change(function () {

    //console.info(  $(this).attr('href') );
    var section4 = $(this).attr('data-id');
    $(".my-form-radio span").removeClass("active");
    $(this).next().addClass("active");
    $('.dinamic-form-content').hide();
    $(section4).fadeIn(800);

});

NOTE: style is not on radio but on span next to it. 注意:样式不在广播中,而是在其旁边的跨度上。

Here is a solution that does not require javascript, only css. 这是不需要javascript的解决方案,仅需要CSS。

 input[type=radio] {
            display:none; 
            margin:10px;
        }

    input[type=radio] {
        display:inline-block;
        margin:-2px;
        padding: 4px 12px;
        background-color: #e7e7e7;
        border-color: #ddd;
    }

    input[type=radio]:checked { 
       background-image: none;
        background-color:#d0d0d0;
    }

Wrap your radios in <label> . 将收音机包裹在<label> Makes it easier to click since clicking anywhere on label will change the radio 单击标签上的任意位置都会更改收音机,因此单击起来更方便

<label for="form-show-item-1" class="active">
     <input data-id="#form-show-item-1" type="radio" name="name" checked /> 
      De Aeroporto para Bairro
</label>

Then you can target the radio parent() 然后您可以定位单选对象parent()

$('.my-form-radio input').change(function() {

      var section4 = $(this).attr('data-id');
        $(".my-form-radio label.active").removeClass("active");
        $(this).parent().addClass("active");
        $('.dinamic-form-content').hide();
        $(section4).fadeIn(800);

  });

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM