【发布时间】:2015-05-12 15:42:13
【问题描述】:
如何获取从我的 div 中选中的单选按钮
这是我的 jquery,但 c 返回未定义
$('#SpaceType').change(function () {
var kids = $(this).children();
$(kids).each(function() {
var c = $(this).data('id');
});
});
这是我的 div
<div class="btn-group" data-toggle="buttons" id="SpaceType">
<label id="SpaceTypeLabelHouse" class="btn btn-primary">
<input type="radio" name="typeoptions" autocomplete="off" id="0"> House
</label>
<label id="SpaceTypeLabelApartment" class="btn btn-primary">
<input type="radio" name="typeoptions" autocomplete="off" id="1"> Apartment
</label>
<label id="SpaceTypeLabelStudio" class="btn btn-primary">
<input type="radio" name="typeoptions" autocomplete="off" id="2"> Studio
</label>
<label id="SpaceTypeLabelOther" class="btn btn-primary">
<input type="radio" name="typeoptions" autocomplete="off" id="3"> Other
</label>
</div>
【问题讨论】:
-
为什么不使用类,那么可以使用
this,因为this会=到用于触发功能的元素。这是使用相同方法的东西 一个函数 stackoverflow.com/questions/28969021/… 和 stackoverflow.com/questions/28954143/…
标签: javascript jquery html