zoukankan      html  css  js  c++  java
  • jquery收集表单数组及去掉字符串最后的逗号!

    jquery收集表单数组:

    <input type='text' name='one[]' value='' /><br>
    <input type='text' name='one[]' value='' /><br>
    <input type='text' name='one[]' value='' /><hr>
    <input type='text' name='two[]' value='' /><br>
    <input type='text' name='two[]' value='' /><br>
    <input type='text' name='two[]' value='' /><br>
    <input type='button' value='提交' >
    <script type='text/javascript'>
    (function(){
        var oneval = twoval = '';
        $("input[type='button']").click(function(){
            $("input[name='one[]']").each(function(index,element){            
                oneval += $(this).val()+',';
            });
            oneval = oneval.substring(0,oneval.length-1);
            $("input[name='two[]']").each(function(index,element){
                twoval += $(this).val()+',';
            });
            twoval = twoval.substring(0,twoval.length-1);
            console.log(oneval);
            console.log(twoval);
        });
    })();
    </script>

    掉字符串最后的逗号:

    twoval = twoval.substring(0,twoval.length-1);
  • 相关阅读:
    算法70----只有两个键的键盘【动态规划】
    Shell
    Shell
    Shell
    Shell
    Shell
    Tools
    Jenkins
    Java
    Product
  • 原文地址:https://www.cnblogs.com/e0yu/p/7406426.html
Copyright © 2011-2022 走看看