【问题标题】:Changing input radio into large div boxes将输入单选更改为大 div 框
【发布时间】:2014-02-01 12:43:36
【问题描述】:

我试图弄清楚如何隐藏单选按钮,而是使用 div 框,以便用户可以点击大框而不是小按钮。

这可能吗?

【问题讨论】:

标签: css input radio-button stylesheet


【解决方案1】:

通过单击将divs 与单选按钮相关联,然后您就设置好了。

<div class="radio-wrap"><input type="radio"></div>


$('div.radio-wrap').click(function(e){
  $(this).find('[type=radio]').attr('checked',true);
});

您可以使用 css 隐藏无线电输入或将其移动到您想要的位置。

【讨论】:

    【解决方案2】:

    jQuery UI 提供了一个buttonset 可能起作用的功能:

    <div id="radio"  align="center" >
    <input type="radio" name ="gender" id="male" value="MALE" checked="checked"/><label for="male">MALE</label>
                <input type="radio" name ="gender" id="female" value="FEMALE" /><label for="female">FEMALE</label>
    </div> 
    

    和脚本

    $(function() {
            $( "#radio" ).buttonset();
        });
    

    Demo

    【讨论】:

    • 编辑了您的答案,以便清楚您指的是 jQuery UI,它是 jQuery 的补充。
    • jQuery UI 是否应该自动设置与单选按钮关联的类?我只是通过将其复制并粘贴到我的项目中来测试它,但它没有将单选输入转换为按钮?我的项目中也有 jQuery UI 文件
    • 是的,它会自动为收音机设置类...确保在分配 ID 和标签值时遵循正确的命名法..如演示小提琴中所示
    猜你喜欢
    • 2019-12-25
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2011-08-11
    • 2016-01-27
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多