qq_35514032 2019-04-22 19:35 采纳率: 0%
浏览 479

js如何获取很多个select里面的optin的值 并且把值求和,传递到后台,我现在只会1个一个的获取求指点1。

检查 计算 人:分 房屋:分
提交 返回
<script type="text/javascript">

    function homsave() {

        var name = $("#text1").val(), idcode = $("#text2").val();
        var remarks = $("#text34").val(), bank = $("#text35").val();
        var mtion = $("#text36").val();
        $.ajax({
            type: "POST",   //提交的方法
            url:"/business/save", //提交的地址
            data:$('#homesave').serialize(),// 序列化表单值
            async: false,
            error: function(request) {  //失败的话
                alert("Connection error");
            },
            success: function(data) {  //成功
                alert(data);  //就将返回的数据显示出来
                window.location.href="跳转页面"
            }
        });


        // var name = $("#text1").val(), idcode = $("#text2").val();
        // var remarks = $("#text34").val(), bank = $("#text35").val();
        // var mtion = $("#text36").val();
        // if (remarks == null || remarks == "") {
        //     alert("备注不能为空");
        //     return;
        // }
        // if (bank == null || bank == "") {
        //     $("#text35").val("--");
        // }
        // if (mtion == null || remarks == "") {
        //     $("#text36").val("--");
        // }
        alert(name+idcode)
    }

    function jc() {
        var remarks = $("#text34").val(), bank = $("#text35").val();
        var mtion = $("#text36").val();
        if (remarks == null || remarks == "") {
            $("#text34").val("--");
        }
        if (bank == null || bank == "") {
            $("#text35").val("--");
        }
        if (mtion == null || remarks == "") {
            $("#text36").val("--");
        }
    }

    function js() {

        var text3 = $("#text3").find("option:selected").val();
        var text4 = $("#text4").find("option:selected").val();
        var text5 = $("#text5").find("option:selected").val();
        var text6 = $("#text6").find("option:selected").val();
        var text7 = $("#text7").find("option:selected").val();
        var text8 = $("#text8").find("option:selected").val();
        var text9 = $("#text9").find("option:selected").val();
        var text10 = $("#text10").find("option:selected").val();
        // var text11 = $("#text11").find("option:selected").val();
        var text12 = $("#text12").find("option:selected").val();
        var text13 = $("#text13").find("option:selected").val();
        var text14 = $("#text14").find("option:selected").val();
        var text26 = $("#text26").find("option:selected").val();
        var text27 = $("#text27").find("option:selected").val();
        var text28 = $("#text28").find("option:selected").val();
        var text29 = $("#text29").find("option:selected").val();
        var text30 = $("#text30").find("option:selected").val();
        var text31 = $("#text31").find("option:selected").val();
        var text32 = $("#text32").find("option:selected").val();
        var text33 = $("#text33").find("option:selected").val();
        var menfen = parseInt(text3)+parseInt(text4)+parseInt(text5)+parseInt(text6)
            +parseInt(text7)+parseInt(text8)+parseInt(text9)+parseInt(text10)
            +parseInt(text12)+parseInt(text13)+parseInt(text14);
        var homefen = parseInt(text26)+parseInt(text27)+parseInt(text28)+parseInt(text29)
            +parseInt(text30)+parseInt(text31)+parseInt(text32)+parseInt(text33);
        $("#men").val(menfen);
        $("#home").val(homefen)
    }
</script>
  • 写回答

1条回答 默认 最新

  • 子也 2019-04-22 22:22
    关注

    你用了jquery吧,可以$('select')获取所有的select,然后用foreach遍历把val加起来就行了,多看query的文档很简单的

    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊