开发者

bind problems with radio input in jQuery

Got a binding issue

Excerpt from html code

<table>
    <tr>
        <td haschildren="true"><input id="Grubbel_0" type="radio" name="Grubbel_0" value="0"></td>
        <td haschildren="true"><input id="Grubbel_1" type="radio" name="Grubbel_1" value="1"></td>
    </tr>
</table>

<img src="img.jpg" style="display:none;"/>

Some jQuery

<script language="javascript" type="text/javascript">
    $(document).ready(function () {

        // Check radiobuttons when clickin on a parent table cell
        $("td[haschildren='true']").click(function () {
            $(this).find('input:radio').attr('checked', true);
        });

        // What happens when a radiobutton is changed
        $('*[haschildren="true"] input:radio').bind('change开发者_如何学Python', function () {
            // This does not work when clicking the td boxes
        });
    });
</script>

The bind('change'... works when I click directly on the radio box but not when I click on the td although the radiobox gets checked.

Im using jQuery 1.5.2.

Thanks


Try -

$(document).ready(function () {

    // Check radiobuttons when clickin on a parent table cell
    $("td[haschildren='true']").click(function () {
        $(this).find('input:radio').attr('checked', true).trigger('change');
    });

    // What happens when a radiobutton is changed
    $('*[haschildren="true"] input:radio').bind('change', function () {
        // This does not work when clicking the td boxes
    });
});


A small syntax error change $("td[haschildren="true"]") to $("td[haschildren='true']")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜