我有这样的代码片段,在从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>
答案 0 :(得分:0)
<强>的javascript 强>
function check(val)
{
document.querySelector('.btn.btn-success.dropdown-toggle').innerHTML=val+' <span class="caret"></span>'
}