Why is this simple function not working

前端 未结 3 1288
刺人心
刺人心 2020-12-11 12:55

Why isn\'t this working? Similar code works here: http://www.ralphphillips.com/youtube/stick-figure/stick-figure2.html

But this isn\'t working. I have the html code

3条回答
  •  Happy的楠姐
    2020-12-11 13:10

    I would try this http://jsfiddle.net/EFWf5/1:

    $("form#order :input[type=radio]").each(function(){
        $(this).bind('change', function() {
            checkOptions();
        });
    });
    
    var checkOptions = function () {
        var total = 0;
        var pack = parseInt($('input[name=pack]:checked', '#order').val());
        var accomp = parseInt($('input[name=accomp]:checked', '#order').val());
        if (!isNaN(pack)) total += pack;
        if (!isNaN(accomp)) total += accomp;
        $('#total').text(total);
        $('#title').text($('input[name=pack]:checked', '#order').attr('title'));
    };
    
    Package

    Pack 1
    Pack 2
    Pack 3
    Pack 4
    Pack 5
    Accomp

    1
    2
    3
    4

    Total: 0
    Title:

提交回复
热议问题