如何知道哪一行选择了哪个单选按钮ID? [英] how to know which radio button id selected of which row?
问题描述
我进行了一个演示,其中我创建了ID为tc_1
,tc_2
,tc_3
……的行.
I have make a demo in which I make rows with ids tc_1
, tc_2
, tc_3
…… and so on.
当我展开一行时,我有两个选项和一个按钮.我需要知道选择了哪个行ID和哪个选项?
When I expand a row, I have two options and a button. I need to get know which row id and which option is selected?
示例:我展开第二行,它应使用选项添加测试用例来警告tc_1
.
Example: I expand second row, It should alert tc_1
with option select Add test case.
$('#list').on('click','.addClickClass',function(){
alert('hii')
});
推荐答案
要获取行ID和已检查单选的值,请使用以下命令:
To get the row id and the value of checked radio, use this:
$('#list').on('click','.addClickClass',function(){
alert($(this).parents('li[id*="tc"]').attr('id') + "\n"
+ $(this).parents('.ui-collapsible').find('input:checked').val())
})
它为您提供了这样的输出,例如:
It gives you output like this, for example:
tc_1
TestCommand
我相信这正是您想要的.
which I believe is exactly what you're looking for.
我用它来获取行ID:
$(this).parents('li[id*="tc"]').attr('id')
,以获取检查的单选值:
and this to get the checked radio value:
$(this).parents('.ui-collapsible').find('input:checked').val()
两者都与单击的添加"按钮有关.
Both related to the clicked Add button.
在此处查看其运行情况: http://jsfiddle.net/R2DzV/16/
See it in action here: http://jsfiddle.net/R2DzV/16/
这篇关于如何知道哪一行选择了哪个单选按钮ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!