首页 > Web开发 > 详细

each jquery

时间:2018-01-12 23:20:22      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:move   light   点击切换   post   func   正整数   val   div   this   

        <div class="first">
            <span>投保人数:</span>
            <input type="text" id="people_num" placeholder="预计投保人数" value="1">  人
        </div>
        <div class="first" style="height: auto;">
            <span class="span2">投保方案:</span>
            <div class="button_main">
                
                    
                    <div class="button" data-price="1000.55">方案一</div>
                    
                    <div class="button" data-price="2000">方案二</div>
                    
                    <div class="button" data-price="3000">方案三</div>
                    
                
            </div>
        </div>
        <div class="bottom_button" id="to_calculate">
            立即计算
        </div>

  

 

//计算价格
function calculation_price(){
    var people_num = parseInt($(‘#people_num‘).val());
    if(people_num < 0){
        console.log("人数错误");
        return false;
    }
    if (!$(‘.button_main div‘).hasClass(‘button_selected‘)){
        $(‘.button_main .button:first‘).addClass(‘button_selected‘);
    }

    $(‘.button‘).each(function(index){
        var _this = $(this);
        var _select_price = parseFloat(_this.data(‘price‘));
        if(_this.hasClass(‘button_selected‘)){
            var _select_price = parseFloat(_this.data(‘price‘));
            var total_fee = _select_price * people_num;
            $(‘#total_fee‘).html(total_fee + ‘元‘);
        }
    });
}

// $(document).on(‘click‘,‘#to_calculate‘,function () {
//     $(‘.calculation_result‘).fadeIn();
// });

//点击切换方案
$(document).on(‘click‘,‘.button‘,function () {
    if($(‘.button‘).has(‘button_selected‘)){
        $(‘.button‘).removeClass(‘button_selected‘);
    }
    $(this).addClass(‘button_selected‘);
    calculation_price();
});
//变换投保人数
$(document).on(‘change‘,‘#people_num‘,function(){
    var people_num = $(‘#people_num‘).val();
    console.log(people_num);
    if(!(/(^[1-9]\d*$)/.test(people_num))){
        alert("投保人数仅可为正整数");
        $(‘#people_num‘).val(‘1‘);
        return false;
    }
    calculation_price();
});

  

each jquery

标签:move   light   点击切换   post   func   正整数   val   div   this   

原文:https://www.cnblogs.com/pansidong/p/8277869.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号