问题描述
我已经动态创建了20个单选按钮
I have created 20 radio button dynamically
<script>
$(function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable"
}).disableSelection();
$( "#sortable2" ).sortable({
remove: function(event, ui) {
t = ui.item[0].attributes['id'].nodeValue;
k = $("input[name='"+t+"' ]");
k.remove();
},
receive: function(event, ui) {
//itemid = ui.item[0].attributes['id'];
t = ui.item[0].attributes['id'].nodeValue;
$("#element").append( "<br/>" +ui.item[0].innerHTML.trim() );
for(i=1; i<=20; i++)
{
j=$("#over" + i).append("<br/> <td><input type=radio name='"+ui.item[0].innerHTML.trim()+"' value='"+i+"'></td> <br/>");
var radVal=$("#over" + i+":checked").val();
alert(radVal);
}
}
});
});
`'玩家';
for($ j = 1; $ j< = 20; $ j ++)
for($j=1;$j<=20;$j++)
{
echo '<th align="center">'.$j.'</th>';
}
回声'';
回显";{ 回显";回显";回显";
echo "";{ echo "";echo "";echo "";
for($ i = 1; $ i< = 20; $ i ++) { 回声";
回声";
回显"; }
} 回声";
for($i = 1; $i <=20; $i++) { echo "";
echo "";
echo ""; }
} echo "";
?>`
我的问题是如何检查验证值
my question is that how to check validation value
推荐答案
将生成单选按钮的代码更改为:(添加value属性)
Change the code where you generate the radiobutton to: (Add the value attribute)
<input type=radio name='"+ui.item[0].innerHTML.trim()+"' value='"+i+"'>
添加所有单选按钮后,如果您在任何点击事件中都调用了此功能
After adding all the radio button if you call this function on any click event
function getChecked(){
var radVal=$("input[name=nameOfRadiobuttons]:checked").val();
alert(radVal);
}
在HTML页面上放置一个按钮以调用该函数
Put a button on th HTML Page calling the function
<input type=button onclick='getChecked()'>
radVal将给出所选复选框的索引.如果未定义,则您可能未选中任何单选按钮
radVal will give the index of the checkbox selected..If its undefined then you might not have checked any radio button
这篇关于jQuery动态单选按钮验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!