选择单选按钮时更新按钮显示

时间:2016-05-06 02:30:18

标签: javascript jquery html twitter-bootstrap

我有这样的代码片段,在从jan / feb / mar这样的单选按钮列表中选择一个选项时,按钮应该更新。怎么做?

<div class="btn-group pull-left" style="margin-left:72px;">
    <button class="btn btn-success" align="center">Action</button>
    <button class="btn btn-success dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                        </button>
    <ul class="dropdown-menu dropdown-menu-right">
        <label><input type="radio" name="optradio" value = "jan" onclick="check(this.value)">jan</label>
        </br>
        <label><input type="radio" name="optradio" value = "feb" onclick="check(this.value)">feb</label>
        </br>
        <label><input type="radio" name="optradio" value = "mar" onclick="check(this.value)">mar</label>
        </br>
    </ul>
</div>

<script type="text/javascript">
function check(val)
{
    $(".dropdown-menu li a").parents('.btn-group').find('.dropdown-toggle').html(val+' <span class="caret"></span>') 
}              
</script>

1 个答案:

答案 0 :(得分:0)

<强>的javascript

function check(val)
{
    document.querySelector('.btn.btn-success.dropdown-toggle').innerHTML=val+' <span class="caret"></span>'
}

How to select classes with spaces

http://www.w3schools.com/jquery/jquery_ref_selectors.asp