This question already has answers here:
Is there a CSS parent selector?
                                
                                    (31个答案)
                                
                        
                                4年前关闭。
            
                    
我试图弄清楚(经过大量搜索之后)如何在选择其中的一个单选按钮后使div更改颜色。场景是我要两个div并排,基本上说“选择此计划”,在div下方是一个继续注册按钮。因此,当有人单击div之一中的单选按钮(选择会员计划)时,它将更改该div的样式以具有新的背景色和文本颜色。我不知道如何使这项工作。

任何建议将不胜感激!

最佳答案

$( 'input[type=radio]' ).on( 'click', function(){

    var value = $(this).val();

    // now based on value, we do different things to our div...
    // example:
    switch ( value ){
        case 1:
            myDiv.css( 'background-color', 'red' );
            break;
        // next case, and so on....
    }

} );

07-28 02:39
查看更多