jquery Click the table row event and the radio selected event conflict

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.