2 qq 15290009 qq_15290009 于 2016.02.23 16:00 提问

js的问题,大神快来!!!!!!!!!!

图片说明

如何点击 年月日 这三个按钮 就是图片圈住的那个 设置默认值是年 调用js里的计算方法 当选项改变之后结果要改变 当年变成月的时候要除于12 下面的结果也要变了 我用了onclick="Costcalculator" 这个方法 但是调用不起来 让大神们帮我看看 什么问题 怎么回事 又改怎么改好呢 感谢了 详细说

js html 我贴在下面吧

js计算方法是重复的

6个回答

qq_15290009
qq_15290009   2016.02.23 16:03
已采纳
  <tr>
                                                                                                        <td>利率选项: </td>
                                                                                                        <td>
                                                                                                            <div class="sortNum">
                                                                                                            <input type="radio" id="1-5" class="sortNum1" name="standard1"  onclick="Costcalculator1"/>日利率

                                                                                                            <input type="radio" id="1-4" class="sortNum1" name="standard1"   />月利率

                                                                                                                <input type="radio" id="1-6" class="sortNum1" name="standard1"  onclick="Costcalculator" /> 年利率     
                                                                                                            </div>


                                                                                                        </td>

                                                                                                    </tr>

js **


 $(document).ready(function () {
      //显示当前日期
    var d = new Date();
    var s2 = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
    $('#EntTime30').val(s2);

     //显示截止日期
    var d = new Date();
    var s1 = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
    $('#EntTime31').val(s1);

    //调用id 和id值改变后重新计算

    var input = parseFloat($("#input").val());
    var inprt1 = parseFloat($(" #input1").val());
    Costcalculator(input,input1);
    Costcalculator1(input,input1);
    //Costcalculator2(input,input1);


    $("#input").change(function(){
        input = parseFloat($( this).val());

        Costcalculator(input,input1);
        });
    $("#input1").change(function(){
        input1 = parseFloat($(this).val());
        Costcalculator(input,input1);
        })

    $('[id^="input"],[id^="lj"],[id^="lj1"],[id^="lj2"],[id^="lj3"],[id^="lj4"],[id^="lj5"],[id^="lj6"],[id^="lj7"],[id^="lj8"],[id^="lj9"],[id^="lj10"],[id^="lj11"],[id^="lj12"],[id^="lj13"],[id^="input1"]').val('');
 });


 function Costcalculator(input,input1){
     input = parseFloat(input) || 0;
     input1 = parseFloat(input1) || 0;

     var al = 0;
     var sl = 0;
     var dl = 0;
     var el = 0;
     var fl = 0;
     var gl = 0;
     var hl = 0;
     var jl = 0;
     var kl = 0;
     var ll = 0;
     var ql = 0;
     var wl = 0;

        //受理费全额 半额计算
        if(input<=10000){ 

            al =  (input*input1/100)+50;

            sl = [(input*input1/100)+50]/2;

        }else if(input>10000 && input<=100000){

            al = [(input-10000)*2.5/100+50]*input1/100;


            sl = [(input-10000)*2.5/100+50]*input1/100/2;

        }else if(input>100000 && input<=200000){
            al = [(input-100000)*2/100+50]*input1/100;


            sl = [(input-100000)*2/100+50]*input1/100/2;

        }else if(input>200000 && input<=500000){
            al = [(input-200000)*1.5/100+50]*input1/100;


            sl = [(input-200000)*1.5/100+50]*input1/100/2;

        }else if(input>500000 && input<=1000000){
            al = [(input-500000)*1/100+50]*input1/100;


            sl = [(input-500000)*1/100+50]*input1/100/2;

        }else if(input>1000000 && input<=2000000){
            al = [(input-1000000)*0.9/100+50]*input1/100;


            sl = [(input-1000000)*0.9/100+50]*input1/100/2;

        }else if(input>2000000 && input<=5000000){
            al = [(input-2000000)*0.8/100+50]*input1/100;


            sl = [(input-2000000)*0.8/100+50]*input1/100/2;

        }else if(input>5000000 && input<=10000000){
            al = [(input-5000000)*0.7/100+50]*input1/100;


            sl = [(input-5000000)*0.7/100+50]*input1/100/2;

        }else if(input>10000000 && input<=20000000){
            al = [(input-10000000)*0.6/100+50]*input1/100;


            sl = [(input-10000000)*0.6/100+50]*input1/100/2;

        }else{
            al = [(input-20000000)*0.5/100+50]*input1/100;


            sl = [(input-20000000)*0.5/100+50]*input1/100/2;

        }

        //离婚计算
        if(input<=200000){

            dl = input*input1/100+100

            el = [(input*input1/100)+100]/2

        }else{
            dl = [(input-200000)*0.5/100+100]*input1/100;

            el = [(input-200000)*0.5/100+100]*input1/100/2;
            }


            var lj = 0;
            lj = al+dl;
            $("#lj").val(lj.toFixed(2));

            var lj7 = 0;
            lj7 = sl+el;
            $("#lj7").val(lj7.toFixed(2));

        //人格计算
        if(input<=50000){
            fl = input*input1/100+500;

            gl = [(input*input1/100)+500]/2;
        }else if(input>50000 && input<=100000){
            fl = [(input-50000)*1/100+500]*input1/100;

            gl = [(input-50000)*1/100+500]*input1/100/2;
        }else{
            fl = [(input-100000)*0.5/100+500]*input1/100;

            gl = [(input-100000)*0.5/100+500]*input1/100/2;
            }

            var lj1 = 0;
            lj1 = al+fl;
            $("#lj1").val(lj1.toFixed(2));

            var lj8 = 0;
            lj8 = sl+gl;
            $("#lj8").val(lj8.toFixed(2));
        //执行案件
        if(input<=10000){
            hl = input*input1/100+50;

            jl = [(input*input1/100)+50]/2;
        }else if(input>10000 && input<=500000){
            hl = [(input-10000)*1.5/100+50]*input1/100;

            jl = [(input-10000)*1.5/100+50]*input1/100/2;
        }else if(input>500000 && input<=5000000){
            hl = [(input-500000)*1/100+50]*input1/100;

            jl = [(input-500000)*1/100+50]*input1/100/2;
        }else if(input>5000000 && input<=10000000){
            hl = [(input-5000000)*0.5/100+50]*input1/100;

            jl = [(input-5000000)*0.5/100+50]*input1/100/2;
        }else{
            hl = [(input-10000000)*0.1/100+50]*input1/100;

            jl = [(input-10000000)*0.1/100+50]*input1/100/2;
            }

            var lj2 = 0;
            lj2 = al+hl;
            $("#lj2").val(lj2.toFixed(2));

            var lj9 = 0;
            lj9 = sl+jl;
            $("#lj9").val(lj9.toFixed(2));

        //财产计算
        if(input<=1000){
            kl = input*input1/100+30;

            ll = [(input*input1/100)+30]/2
        }else if(input>1000 && input<=100000){
            kl = [(input-1000)*1/100+30]*input1/100;

            ll = [(input-1000)*1/100+30]*input1/100/2;
        }else {
            kl = [(input-100000)*0.5/100+30]*input1/100;

            ll = [(input-100000)*0.5/100+30]*input1/100/2;
            }
            var lj3 = 0;
            lj3 = al+kl;
            $("#lj3").val(lj3.toFixed(2));

            var lj10 = 0;
            lj10 = sl+ll;
            $("#lj10").val(lj10.toFixed(2));

        //支付令计算
        if(input<=10000){
            ql = [(input*input1/100+50)]/3;

            wl = [(input*input1/100+50)/3]/2
        }else if(input>10000 && input<=100000){
            ql = [(input-10000)*2.5/100+50]/3*input1/100;

            wl = [(input-10000)*2.5/100+50]/3*input1/100/2;
        }else if(input>100000 && input<=200000){
            ql = [(input-100000)*2/100+50]/3*input1/100;

            wl = [(input-100000)*2/100+50]/3*input1/100/2;
        }else if(input>200000 && input<=500000){
            ql = [(input-200000)*1.5/100+50]/3*input1/100;

            wl = [(input-200000)*1.5/100+50]/3*input1/100/2;
        }else if(input>500000 && input<=1000000){
            ql = [(input-500000)*1/100+50]/3*input1/100;

            wl = [(input-500000)*1/100+50]/3*input1/100/2;
        }else if(input>1000000 && input<=2000000){
            ql = [(input-1000000)*0.9/100+50]/3*input1/100;

            wl = [(input-1000000)*0.9/100+50]/3*input1/100/2;
        }else if(input>2000000 && input<=5000000){
            ql = [(input-2000000)*0.8/100+50]/3*input1/100;

            wl = [(input-2000000)*0.8/100+50]/3*input1/100/2;   
        }else if(input>5000000 && input<=10000000){
            ql = [(input-5000000)*0.7/100+50]/3*input1/100; 

            wl = [(input-5000000)*0.7/100+50]/3*input1/100/2;
        }else if(input<10000000 && input<=20000000){
            ql = [(input-10000000)*0.6/100+50]/3*input1/100;

            wl = [(input-10000000)*0.6/100+50]/3*input1/100/2;
        }else{
            ql = [(input-20000000)*0.5/100+50]/3*input1/100;

            wl = [(input-20000000)*0.5/100+50]/3*input1/100/2;
            }

            var lj4 = 0;
            lj4 = al+ql;
            $("#lj4").val(lj4.toFixed(2));

            var lj11 = 0;
            lj11 = sl+wl;
            $("#lj11").val(lj11.toFixed(2));
     }


function Costcalculator1(input,input1){
     input = parseFloat(input) || 0;
     input1 = parseFloat(input1) || 0;

     var al = 0;
     var sl = 0;
     var dl = 0;
     var el = 0;
     var fl = 0;
     var gl = 0;
     var hl = 0;
     var jl = 0;
     var kl = 0;
     var ll = 0;
     var ql = 0;
     var wl = 0;

        //受理费全额 半额计算
        if(input<=10000){ 

            al =  (input*input1/100)+50;

            sl = [(input*input1/100)+50]/2;

        }else if(input>10000 && input<=100000){

            al = [(input-10000)*2.5/100+50]*input1/100;


            sl = [(input-10000)*2.5/100+50]*input1/100/2;

        }else if(input>100000 && input<=200000){
            al = [(input-100000)*2/100+50]*input1/100;


            sl = [(input-100000)*2/100+50]*input1/100/2;

        }else if(input>200000 && input<=500000){
            al = [(input-200000)*1.5/100+50]*input1/100;


            sl = [(input-200000)*1.5/100+50]*input1/100/2;

        }else if(input>500000 && input<=1000000){
            al = [(input-500000)*1/100+50]*input1/100;


            sl = [(input-500000)*1/100+50]*input1/100/2;

        }else if(input>1000000 && input<=2000000){
            al = [(input-1000000)*0.9/100+50]*input1/100;


            sl = [(input-1000000)*0.9/100+50]*input1/100/2;

        }else if(input>2000000 && input<=5000000){
            al = [(input-2000000)*0.8/100+50]*input1/100;


            sl = [(input-2000000)*0.8/100+50]*input1/100/2;

        }else if(input>5000000 && input<=10000000){
            al = [(input-5000000)*0.7/100+50]*input1/100;


            sl = [(input-5000000)*0.7/100+50]*input1/100/2;

        }else if(input>10000000 && input<=20000000){
            al = [(input-10000000)*0.6/100+50]*input1/100;


            sl = [(input-10000000)*0.6/100+50]*input1/100/2;

        }else{
            al = [(input-20000000)*0.5/100+50]*input1/100;


            sl = [(input-20000000)*0.5/100+50]*input1/100/2;

        }

        //离婚计算
        if(input<=200000){

            dl = input*input1/100+100

            el = [(input*input1/100)+100]/2

        }else{
            dl = [(input-200000)*0.5/100+100]*input1/100;

            el = [(input-200000)*0.5/100+100]*input1/100/2;
            }


            var lj = 0;
            lj = (al+dl)/365;
            $("#lj").val(lj.toFixed(2));

            var lj7 = 0;
            lj7 = (sl+el)/365;
            $("#lj7").val(lj7.toFixed(2));

        //人格计算
        if(input<=50000){
            fl = input*input1/100+500;

            gl = [(input*input1/100)+500]/2;
        }else if(input>50000 && input<=100000){
            fl = [(input-50000)*1/100+500]*input1/100;

            gl = [(input-50000)*1/100+500]*input1/100/2;
        }else{
            fl = [(input-100000)*0.5/100+500]*input1/100;

            gl = [(input-100000)*0.5/100+500]*input1/100/2;
            }

            var lj1 = 0;
            lj1 = (al+fl)/365;
            $("#lj1").val(lj1.toFixed(2));

            var lj8 = 0;
            lj8 = (sl+gl)/365;
            $("#lj8").val(lj8.toFixed(2));
        //执行案件
        if(input<=10000){
            hl = input*input1/100+50;

            jl = [(input*input1/100)+50]/2;
        }else if(input>10000 && input<=500000){
            hl = [(input-10000)*1.5/100+50]*input1/100;

            jl = [(input-10000)*1.5/100+50]*input1/100/2;
        }else if(input>500000 && input<=5000000){
            hl = [(input-500000)*1/100+50]*input1/100;

            jl = [(input-500000)*1/100+50]*input1/100/2;
        }else if(input>5000000 && input<=10000000){
            hl = [(input-5000000)*0.5/100+50]*input1/100;

            jl = [(input-5000000)*0.5/100+50]*input1/100/2;
        }else{
            hl = [(input-10000000)*0.1/100+50]*input1/100;

            jl = [(input-10000000)*0.1/100+50]*input1/100/2;
            }

            var lj2 = 0;
            lj2 = (al+hl)/365;
            $("#lj2").val(lj2.toFixed(2));

            var lj9 = 0;
            lj9 = (sl+jl)/365;
            $("#lj9").val(lj9.toFixed(2));

        //财产计算
        if(input<=1000){
            kl = input*input1/100+30;

            ll = [(input*input1/100)+30]/2
        }else if(input>1000 && input<=100000){
            kl = [(input-1000)*1/100+30]*input1/100;

            ll = [(input-1000)*1/100+30]*input1/100/2;
        }else {
            kl = [(input-100000)*0.5/100+30]*input1/100;

            ll = [(input-100000)*0.5/100+30]*input1/100/2;
            }
            var lj3 = 0;
            lj3 = (al+kl)/365;
            $("#lj3").val(lj3.toFixed(2));

            var lj10 = 0;
            lj10 = (sl+ll)/365;
            $("#lj10").val(lj10.toFixed(2));

        //支付令计算
        if(input<=10000){
            ql = [(input*input1/100+50)]/3;

            wl = [(input*input1/100+50)/3]/2
        }else if(input>10000 && input<=100000){
            ql = [(input-10000)*2.5/100+50]/3*input1/100;

            wl = [(input-10000)*2.5/100+50]/3*input1/100/2;
        }else if(input>100000 && input<=200000){
            ql = [(input-100000)*2/100+50]/3*input1/100;

            wl = [(input-100000)*2/100+50]/3*input1/100/2;
        }else if(input>200000 && input<=500000){
            ql = [(input-200000)*1.5/100+50]/3*input1/100;

            wl = [(input-200000)*1.5/100+50]/3*input1/100/2;
        }else if(input>500000 && input<=1000000){
            ql = [(input-500000)*1/100+50]/3*input1/100;

            wl = [(input-500000)*1/100+50]/3*input1/100/2;
        }else if(input>1000000 && input<=2000000){
            ql = [(input-1000000)*0.9/100+50]/3*input1/100;

            wl = [(input-1000000)*0.9/100+50]/3*input1/100/2;
        }else if(input>2000000 && input<=5000000){
            ql = [(input-2000000)*0.8/100+50]/3*input1/100;

            wl = [(input-2000000)*0.8/100+50]/3*input1/100/2;   
        }else if(input>5000000 && input<=10000000){
            ql = [(input-5000000)*0.7/100+50]/3*input1/100; 

            wl = [(input-5000000)*0.7/100+50]/3*input1/100/2;
        }else if(input<10000000 && input<=20000000){
            ql = [(input-10000000)*0.6/100+50]/3*input1/100;

            wl = [(input-10000000)*0.6/100+50]/3*input1/100/2;
        }else{
            ql = [(input-20000000)*0.5/100+50]/3*input1/100;

            wl = [(input-20000000)*0.5/100+50]/3*input1/100/2;
            }

            var lj4 = 0;
            lj4 = (al+ql)/365;
            $("#lj4").val(lj4.toFixed(2));

            var lj11 = 0;
            lj11 = (sl+wl);
            $("#lj11").val(lj11.toFixed(2));
     }

gllstc
gllstc   2016.02.23 16:21

浏览器报错是什么?用$("#1-6").click(function(){})试一试?

gllstc
gllstc 回复热呛: 如果不行的话,就要进行断点调试啦,浏览器没报错好麻烦╮(╯▽╰)╭
接近 2 年之前 回复
gllstc
gllstc 回复热呛: 恩恩,试一试可以吗,不过看你的代码id=“1-6”,对应的是Costcalculator方法吧,$("#1-6").click(function( Costcalculator){计算方法})这样
接近 2 年之前 回复
qq_15290009
qq_15290009 没有报错 在js里吗 $("#1-6").click(function( Costcalculator1){计算方法})这样吗 ??
接近 2 年之前 回复
showbo
showbo   Ds   Rxr 2016.02.23 16:35

添加click事件,记住默认点击的项,然后计算下比率后更新input的值,注意修改选择器

 <tr>
    <td>利率选项: </td>
    <td>
        <div class="sortNum">
            <input type="radio" id="1-5" class="sortNum1" name="standard1" />日利率

            <input type="radio" id="1-4" class="sortNum1" name="standard1" />月利率

            <input type="radio" id="1-6" class="sortNum1" name="standard1" /> 年利率
        </div>


    </td>

</tr>
<script>

    $(document).ready(function () {
        var radioIndex = 2;//记住radio位置,默认为2 年率
        $(':radio[id^="1-"]').click(function () {
            var index = $(this).index()//获取点击的radio下标
            , rate = 1;//切换时的倍率

            if (radioIndex != index) {//不是同一个
                if (radioIndex == 2) { if (index == 0) rate = 1 / 365; else rate = 1 / 12; }//年到月日转换
                else if (radioIndex == 1) { if (index == 0) rate = 1 / 30; else rate = 12; }//月到日年转换
                else { if (index == 1) rate = 30; else rate = 365;}//日到月年转换

                $('需要重新计算的值的input的选择器').val(function () {
                    return (parseFloat(this.value) * rate).toFixed(2);
                });

                radioIndex=index//更新利率选项下标
            }
        });
</script>
qq_15290009
qq_15290009 html 在下面 我全发上去了
接近 2 年之前 回复
qq_15290009
qq_15290009 回复无聊码农: 额 就俩个文本框 id 是input 和 input1 剩下的是的到结果的文本框 lj lj1 什么的 哪有那么多啊 算了 我吧html全发上去吧 你帮我看看 在哪个回答 谢谢了
接近 2 年之前 回复
showbo
showbo 回复热呛: 其他的html代码要发啊,就是那些要计算的,而且一个事件处理函数就行了,写那么多个Costcalculator1干嘛
接近 2 年之前 回复
qq_15290009
qq_15290009 http://ask.csdn.net/questions/238664#answer_220791 我把改过之后发在这里 还是有问题 你帮我看看 解决了俩个一起采纳
接近 2 年之前 回复
qq_15290009
qq_15290009 哦哦 明白了
接近 2 年之前 回复
showbo
showbo 回复热呛: 就是你要更新的input的选择器啊,$('#lj,#lj1,#lj2,#lj3,#lj4').val...
接近 2 年之前 回复
qq_15290009
qq_15290009 就是那个 需要从新选择计算容器的那块 我没搞明白
接近 2 年之前 回复
qq_15290009
qq_15290009 ”需要重新计算的值的input的选择器“这个要改成需要更新的input选择器 就书这个要怎么改 你写一下我看看 谢谢
接近 2 年之前 回复
qq_15290009
qq_15290009 回复无聊码农: 调用$(this).index()就得到input所在父容器中所处的位置,”需要重新计算的值的input的选择器“这个要改成需要更新的input选择器 这块没懂
接近 2 年之前 回复
showbo
showbo 回复热呛: 不需要。。调用$(this).index()就得到input所在父容器中所处的位置,”需要重新计算的值的input的选择器“这个要改成需要更新的input选择器
接近 2 年之前 回复
qq_15290009
qq_15290009 var radioIndex = 2;//记住radio位置,默认为2 年率 这个要把 type = radio 填上1 2 3吗 $('需要重新计算的值的input的选择器').val(function () { 还有这个是就是写上那个方法名字呗
接近 2 年之前 回复
sinat_31535993
sinat_31535993   Rxr 2016.02.23 17:09

最简单的办法就是给每一个单选绑定一个事件,单击触发计算。

qq_15290009
qq_15290009 知道 但是我没弄对 能写下例子吗
接近 2 年之前 回复
Royal_lr
Royal_lr   Ds   Rxr 2016.02.23 17:16

通过radio的值进行判断,,,

qq_15290009
qq_15290009 请写下例子 谢谢
接近 2 年之前 回复
qq_15290009
qq_15290009   2016.02.24 14:06

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!