我做的是一个在输入框输入字的时候同时显示输入了多少个字,在IE下运行正常,但到firefox下就死掉了,代码是这样的
    <html>
    <head> <title>jishu</title> 
    <script language="javascript">
     funtion check(strInput)
       { 
         var num=0;
         var reg=/\b/g;        while(reg.exec(strInput))
         num++;          if(navigator.appName.indexOf("Explorer") >-1)
    { 
          document.getElementById('txt').innerText = num/2; 
               } 
         else
                  { 
           document.getElementById('txt').textContent = num/2;   
             }         }
       </script>
      </head>
       <input id="txt" >
      <body > 
    <textarea cols="15" rows="25" onkeydown="check(this.value)" onblur="chec(this.value)"></textarea> 
     <input type="text" value="" id="txt"> 
    </body> 
    </html> 
  

解决方案 »

  1.   

          if(navigator.appName.indexOf("Explorer") >-1)
        {
              document.getElementById('txt').value= num/2; 
                  }
            else
                      {
              document.getElementById('txt').value= num/2;   
                }        } 
      

  2.   

    go get Firefox addon "Firebug"
      

  3.   

    给楼主一个正确的<html> 
        <head> <title>jishu </title> 
        <script language="javascript"> 
        function check(str) 
          { 
    $("show").innerHTML = str.length
            } 
    function $(id)
    {
    return document.getElementById(id);
    }
          </script>
          </head> 
          <body > 
        <textarea id="txt" cols="15" rows="25" onkeyup="check($('txt').value)" onblur="check($('txt').value)"></textarea> 
    <div id="show"></div>
        </body> 
        </html> 
      

  4.   

    document.getElementById('txt').innerText = num/2;
    改为:document.getElementById('txt').innerHTML = num/2; 
    innerText在firefox中无效
      

  5.   

        while(reg.exec(strInput)) 死循环.看不出实现什么功能~~~~~~~~``
      

  6.   

    测试通过.
    测试环境:
    win xp sp3
    ie6
    firefox 2.0.0.14
    代码如下修改完毕。    <html>
        <head> <title>jishu </title>
        <script language="javascript">
        function check(myObj)//strInput)
        {
            var num=0;
            var reg=/\b/g;
    var strInput=myObj.value;
    /*
    while(reg.exec(strInput))
    {
    //strInput=RegExp.rightContext;
            num++;
    }
    */
    var arrMatches =strInput.match(reg);
    num=arrMatches.length;
    document.getElementById('txt').value=num/2;
    /*
            if(navigator.appName.indexOf("Explorer") >-1)
    {
              document.getElementById('txt').innerText = num/2; 
          }
          else
          {
              document.getElementById('txt').textText = num/2;   
          }
    */
    return;    }
          </script>
          </head>
          <body >
    <textarea cols="15" rows="25" onkeyup="javascript:check(this);" onblur="javascript:check(this);"></textarea>
    <input type="text" value="" id="txt" />
        </body>
        </html> 
      

  7.   

    regex代码,在firefox中有问题。
    可能是死循环了。
      

  8.   

    function check(strInput)
    {
      document.getElementById('txt').innerHTML=strInput.value.split(/\s+/).length;
    }
    测试通过 over