Jquery调试问题

Jquery调试问题,jquery,Jquery,我目前正在工作的wp电子商务系统,我已经设法定制它根据我的需要。我现在面临着一个相当恼人的问题。我不太熟悉javascript和jquery,尽管我已经找到了问题所在。不过,我正在努力寻找解决方案 问题是:基于表单选择菜单,会调用一个ajax函数,价格也会发生变化,尽管不是在正确的产品上。相反,它每次都在更改最后一个元素 来自jquery函数的代码片段,我认为它可以处理这个特定方面 // update the price when the variations are altered. jQue

我目前正在工作的wp电子商务系统,我已经设法定制它根据我的需要。我现在面临着一个相当恼人的问题。我不太熟悉javascript和jquery,尽管我已经找到了问题所在。不过,我正在努力寻找解决方案

问题是:基于表单选择菜单,会调用一个ajax函数,价格也会发生变化,尽管不是在正确的产品上。相反,它每次都在更改最后一个元素

来自jquery函数的代码片段,我认为它可以处理这个特定方面

// update the price when the variations are altered.
jQuery(".wpsc_select_variation").live('change', function() {
    jQuery('option[value="0"]', this).attr('disabled', 'disabled');
    parent_form = jQuery(this).parents("form.product_form");
    if ( parent_form.length == 0 )
        return;     
    form_values =jQuery("input[name='product_id'], .wpsc_select_variation",parent_form).serialize( );
    jQuery.post( 'index.php?update_product_price=true', form_values, function(response) {
        var stock_display = jQuery('div#stock_display_' + product_id),
            price_field = jQuery('#product_price_' + product_id),
            price_span = jQuery('#product_price_' + product_id),
            donation_price = jQuery('input#donation_price_' + product_id),
            old_price = jQuery('#old_product_price_' + product_id),
            save = jQuery('#yousave_' + product_id),
            buynow = jQuery('#BB_BuyButtonForm' + product_id);
        if ( response.variation_found ) {
            if ( response.stock_available ) {
                stock_display.removeClass('out_of_stock').addClass('in_stock');
            } else {
                stock_display.addClass('out_of_stock').removeClass('in_stock');
            }
        }

        stock_display.html(response.variation_msg);

        if ( response.price !== undefined ) {
            if (price_field.length && price_field.attr('type') == 'text') {
                price_field.val(response.numeric_price);
            } else {
                price_span.html(response.price);
                old_price.html(response.old_price);
                save.html(response.you_save);
            }
            donation_price.val(response.numeric_price);
        }
    }, 'json');
});
以及显示价格的匹配html的片段

<p class="pricedisplay <?php echo wpsc_the_product_id(); ?>" id="">
                            <!--<?php // _e('Price', 'wpsc'); ?>:-->
                                <span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="currentprice pricedisplay">
                                    <?php echo wpsc_the_product_price(); ?>
                                </span>
</p>
我认为这可能是由于jquery选择了最后一个元素而不是特定的id

我事先非常感谢你的帮助。非常感谢


/nickifrandsen

在javascript代码中,您在哪里设置产品id?我猜是这一行。。。price\u span=jQuery'product\u price\u'+product\u id尽管我不太确定,因为我的javascript语法技能有点差劲。