Original Address: http://zhidao.baidu.com/link?url= HER7LU4JQEJWUHWQO2NQ6LZ6TF7VYHPZRADSL-XABQSF4P4YFTD9VG08SS8HF-1I7XQRALFKRC6TDLHYQIXPCK 2013-01-30 09:10tvogfj | Category: JavaScript | Browse 1779 times
For example:
<tr class= "Resulttr" >
<td><inputtype= "Radio" name= "checkbox" Id= "${personid}" value= "0"/>
<td> Zhang San <td>
<td> Women <td>
</tr>
Use jquery to bind the event, convenient operation, click on the row can be selected radio, get passed to the background;
$ (". Resulttr"). Bind ("click", Function () {
var checkobj = $ (this). Children (). EQ (0). Children (). EQ (0);
if (checkobj.attr (' checked ') ==undefined) {
Checkobj.attr (' checked ', true);
}else{
Checkobj.attr (' checked ', false);
}
});
function can be achieved, but if you click on a row in the radio will not be able to implement the selected, click around a small box, should be an event conflict, what is the best solution?
The questioner is adopted by
First you write this is a problem, when you click on the radio is actually selected, but the event bubbled to TR, and executed a click event, so the election is not the case, in addition, the radio box is not like a check box, there is no need to determine whether the selected state, the code can be optimized to this:
$ ("tr.resulttr"). Bind ("click", Function () {
$ (this). Find ("Input:radio"). attr ("Checked", "checked")
});
-
Questioner evaluation
-
According to what you said, really successful, very happy, thank you!
jquery Click the table row event and the radio selected event conflict