我通過添加下拉菜單來擴展單選按鈕。單選按鈕具有隱藏所有未選中的單選按鈕的滑動效果。但是,當我添加單選按鈕的下拉菜單下拉不起作用。使用單選按鈕時無法使下拉工作正常
的Html
<form>
<group class="inline-radio">
<div>
<input id="opt1" type="radio" name="title">
<label>opt1</label>
</div>
<div>
<input id="opt2" type="radio" name="title">
<label>opt2</label>
</div>
<div>
<input id="opt3" type="radio" name="title">
<label>opt3</label>
</div>
<div>
<input id="opt4" type="radio" name="title">
<label>opt4</label>
</div>
<!-- DropDown -->
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Others
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<!-- DropDown End-->
</group>
<span>Please choose one</span>
</form>
的JavaScript
//for toggling
var hid = false;
$("group.inline-radio").click(function() {
if (hid == false) {
$('group.inline-radio').find('input[type="radio"]').not(':checked').parent().hide().find('label').hide();
hid = true;
return;
} else {
$('group.inline-radio').find('input[type="radio"]').not(':checked').parent().show().find('label').show();
hid = false;
}
});
$("input:radio[name=title]").click(function() {
var id= $(this).attr('id');
var value;
var value;
$("input:radio[name=title]")
switch (id) {
case "opt1":
value = "opt1";
break;
case "opt2":
value = "opt2";
break;
case "opt3":
value = "opt3";
break;
case "opt4":
value = "opt4";
break;
case "opt5":
value = "opt5";
break;
case "opt6":
value = "opt6";
break;
case "opt7":
value = "opt7";
break;
default:
value = "Please choose an option";
}
$("span").text(value);
});
這裏是codepen http://codepen.io/flyingboy007/pen/wKpWoY
謝謝...認爲這是javascript問題,並與那個混亂..順便感謝指出跨度問題..當我添加下拉,這是一個跨度,並沒有注意到它.. :) – Abhilash
沒問題 - 花了一段時間的工作與它破碎的功能。項目祝你好運。 –