简体   繁体   中英

jQuery radio button check action doesn't fire

I have the following jquery code:

$("input[name=weight_goal_type]:radio").click(function () {
    alert('it worked');
});

I have also tried:

$("input[name=weight_goal_type]:radio").change(function () {
    alert('it worked');
});

I have also tried to do:

$("#id_weight_goal_type_1").change(function () {
        alert('it worked');
    });

My radio group looks like this:

<li>
    <div class="goal_left_box">
        <div class="dc_box_input">
        <input checked="checked" class="rd-input" id="id_weight_goal_type_0" name="weight_goal_type" type="radio" value="0" />
            <input type="radio" class="rd_input" name="name-a1">
            <span></span>
        </div>
        Maintain Weight
     </div>  

    <div class="cl"></div>
</li>

<li>
    <div class="goal_left_box">
        <div class="dc_box_input">
        <input class="rd-input" id="id_weight_goal_type_1" name="weight_goal_type" type="radio" value="1" />
            <input type="radio" class="rd_input" name="name-a1">
            <span></span>
        </div>
        Lose Weight
     </div>  

    <div class="right_select prst_box wight_box">
        <label>Pounds Per Week</label>
        <div class="prst_box_input">
        <input class="wight" id="id_weight_change_increment" name="weight_change_increment" step="0.01" type="number" value="0.00" />  lbs
        </div>
    </div>

    <div class="cl"></div>
</li>

Here is a fiddle.. http://jsfiddle.net/4naznyu3/

I don't know why this does not fire. What am I doing wrong?

问题是Noah Huppert指出我的html被破坏了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM