0
var user;
(function (user) {
    user = {
        dynamicPriceChange: function () {
            $("input[name='user[plan_id]']").change(function (e) {
                var planId = $(this).data('text');
                var durationPlan = $('p#durSubsMY')[0].innerHTML;
                var price = $('.price')[0].innerHTML;
                $('.price').text(planId);
                $('span#Love')[0].innerHTML = price;
                if price == "29" {
                    durationPlan = "per month";
                }
                if price == "261" {
                    durationPlan = "per year";
                }
            });
        }
        jQuery(function () {
            user.dynamicPriceChange();
        });
    })(user)

如果价格为 29,我尝试更改durationPlan为“每月”,如果价格为 261,我尝试更改为“每年”
。但我无法更改。请帮忙,我是 jQuery 新手。

工作更正的代码是

    if (price == "29") {
         $('p#durSubsMY')[0].innerHTML = "per month"
        }
    if (price == "261" ){
         $('p#durSubsMY')[0].innerHTML = "per year"
        }

谢谢大家的帮助!!!

干杯!:-)

4

3 回答 3

2

As #Adil mentioned, you forgot you parenthesis in the if statement. Also you can try html() function from the jQuery library http://api.jquery.com/html/ instead of innerHTML.

var planId = $(this).data('text'); if you want to get the value from the input use var planId = $(this).val()

于 2012-12-20T07:49:04.287 回答
2

Wrong syntax of if statement, you missed the if condition part parenthesis.

Change

if price == "29" {
       durationPlan = "per month"
}

if price == "261" { durationPlan = "per year" }

To

if (price == "29") {
      durationPlan = "per month"
}
if (price == "261" ){
     durationPlan = "per year"
}

One of closing bracket is also missing in the end.

Change

})(user)

To

}})(user)
于 2012-12-20T07:42:07.787 回答
2

durationPlan只是一个包含元素的 innerHTML 的变量,改变它的值不会改变元素的内容。试试吧

    if (price == "29") {
        $('p#durSubsMY')[0].innerHTML = "per month"
    }
    else if (price == "261") {
        $('p#durSubsMY')[0].innerHTML = "per year"
    }
于 2012-12-20T07:43:05.293 回答