a1.value.match(/\|\|/g).length也不行

解决方案 »

  1.   

    document.getElementById("a1").value.match(/\|\|/g).length
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function xlh(){
    var a1 = document.getElementById("a1");
    var re = /||/g;
    var arr = a1.value.split("||");
    alert(arr.length-1);
    }
    </script>
    </head><body>
    <input id="a1" value="ac23||ac23||ac23||ac23||" />
    <input type="button" value="开始" onclick="xlh()" />
    </body>
    </html>