[英]list-group in form element - bootstrap 3
I read Bootstrap 3 documentation on form and supported controls in forms. 我阅读了表单上的Bootstrap 3文档以及表单中支持的控件。 For selection, I can use
<select>
and <select multiple>
. 对于选择,我可以使用
<select>
和<select multiple>
。
But I want a nicer select-box, exactly like list-group
class bootstrap has. 但是我想要一个更好的选择框,就像
list-group
类引导程序一样。 list-group
can have rendered items, while as the <select>
can only have textual <option>
s. list-group
可以具有渲染项,而<select>
只能具有文本<option>
。
The main idea is so that I can do $("form").serializeArray()
and get all of it as JSON, which apparently will not work if I stick a list-group
as a form control. 主要思想是让我可以执行
$("form").serializeArray()
并将其全部作为JSON来获取,如果我将list-group
作为表单控件使用,这显然将不起作用。
Any ideas on how to do it? 关于如何做的任何想法? Thank you.
谢谢。
Why don't you create what you need with jquery ? 为什么不使用jquery创建所需的内容?
Fiddle : http://bootply.com/113041 小提琴: http : //bootply.com/113041
HTML : HTML:
<select id="myselect" multiple="">
<option val="1">1</option>
<option val="2">2</option>
<option val="3">3</option>
<option val="4">4</option>
<option val="5">5</option>
</select>
JS : JS:
$(document).ready(function(){
$('#myselect').hide().after("<ul class='list-group'></ul>");
$('#myselect option').each(function(){
$('.list-group').append("<li class='list-group-item' opt='"+$(this).attr('val')+"'>"+$(this).html()+"</li>");
});
$('.list-group li').on('click', function(){
$(this).toggleClass('active');
var allVal = new Array();
$('.list-group li.active').each(function(){
allVal.push( $(this).attr('opt' ) );
});
$('#myselect').val(allVal);
});
});
CSS: CSS:
li.active{
background:cyan;
}
Result : A bootstrap list-group, who is linked to your select 结果:一个引导程序列表组,该列表组链接到您的选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.