单击事件自举单选按钮组内没有发射 [英] click event not firing within a bootstrap radio button group
问题描述
创建单选按钮动态和使用上()函数试图捕捉点击用它做什么。
I create radio buttons dynamically and using a on() function try to capture the click and do something with it.
只要我用单选按钮它工作得很好。然后,我封装在一个引导标记内的单选按钮,把它变成一个按钮组 - 现在当我点击按钮的Click事件永远不会触发。不知道我错过了什么!
As long as I used radio buttons it worked fine. I then encapsulated the radio buttons within a bootstrap markup to turn it into a button group - now when I click the button the click event never fires. No idea what I'm missing!
这里的code
这是动态生成的标记
<div id="q_opt" class="btn-group" data-toggle="buttons">
<label class="btn btn-default active" id="d_op_0"> <input id="q_op_0" name="op" type="radio" value="0">22%
</label>
<label class="btn btn-default" id="d_op_1"> <input id="q_op_1" name="op" type="radio" value="1">19%
</label>
<label class="btn btn-default" id="d_op_2"> <input id="q_op_2" name="op" type="radio" value="2">11%
</label>
<label class="btn btn-default" id="d_op_3"> <input id="q_op_3" name="op" type="radio" value="3">42%
</label>
<label class="btn btn-default" id="d_op_4"> <input id="q_op_4" name="op" type="radio" value="4">8%</label>
</div>
下面是通过一个jQuery选择并检查选择了无线,如果点击被解雇的标记
Here's the markup that selects the radio via a jQuery selector and checks if a click was fired
$(document).on('click', 'input:radio[id^="q_op_"]', function(event) {
alert("click fired");
}
时的引导干扰以某种方式 - 还是我失去了一些步骤?我盯着code和我的眼睛不再追赶一个错误。任何帮助/提示AP preciated!
Is bootstrap interfering in some way - or am I missing some step? I'm staring at the code and my eyes aren't catching a mistake anymore. Any help / tips appreciated!
(PS - 单选按钮地转化为一个好看的按钮组,点击上面的按钮并保持pssed对那些$ P $点击等等这样的行为似乎罚款,除了点击不上注册( ..))
(PS - the radio buttons get converted to a nice looking button group, the buttons click and stay pressed on the ones clicked etc. so the behavior seems fine, except that the click isn't registered by on(..) )
推荐答案
使用的变化,而不是处理因点击在标签发生
Use the change handler instead because the click are happening in the label
$(document).on('change', 'input:radio[id^="q_op_"]', function (event) {
alert("click fired");
});
演示:小提琴
这篇关于单击事件自举单选按钮组内没有发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!