经过很长时间的搜索后,我仍然无法找到解决我的问题。从单选按钮获取值select 2
<label class='radio radio-inline'>
<input type='radio' name='roomtype' value ='1' required @if($row['roomtype'] == '1') checked="checked" @endif > Single Room </label>
<label class='radio radio-inline'>
<input type='radio' name='roomtype' value ='2' required @if($row['roomtype'] == '2') checked="checked" @endif > Double Room </label>
<label class='radio radio-inline'>
<input type='radio' name='roomtype' value ='3' required @if($row['roomtype'] == '3') checked="checked" @endif > Triple Room </label>
我想将单选按钮的值传递给select2元素。
$(".select2").select2({ width:"100%", maximumSelectionLength:3 });
对于maximumSelectionLength值,而不是3我想从单选按钮传递值..所以我来此解决方案,但它没有工作
$(".select2").select2({ width:"100%", maximumSelectionLength: $('input[name=roomtype]:checked') });
赞赏任何帮助。感谢
编辑: 我的形式是在模式..不幸的是,这些解决方案并没有为我工作..
你很近。 '$('input [name = roomtype]:checked')。attr('value')'可能有帮助。 – 31piy
不幸的是没有工作..窗体是模态。这可能是为什么?不知道 – stoneshak
你应该展示一些你的代码 - 或者更好地尝试为你的问题创建一个[最小的,完整的和可见的例子](https://stackoverflow.com/help/mcve)。 – gus27