jscript在IE下运行正常但到firefox下就死掉了

hyfei1123 2008-06-02 08:50:46
我做的是一个在输入框输入字的时候同时显示输入了多少个字,在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>

...全文
139 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
bwangel 2008-06-04
  • 打赏
  • 举报
回复
这个不能怪FF
CnEve 2008-06-04
  • 打赏
  • 举报
回复
firefox 不支持 innerText
rainsome 2008-06-04
  • 打赏
  • 举报
回复
regex代码,在firefox中有问题。
可能是死循环了。
rainsome 2008-06-04
  • 打赏
  • 举报
回复
测试通过.
测试环境:
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>
hyfei1123 2008-06-04
  • 打赏
  • 举报
回复
不是死循环
是不是正则的问题啊
rainsome 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 gghunter 的回复:]
while(reg.exec(strInput)) 死循环.看不出实现什么功能~~~~~~~~``
[/Quote]

This is a regex.
gghunter 2008-06-04
  • 打赏
  • 举报
回复
while(reg.exec(strInput)) 死循环.看不出实现什么功能~~~~~~~~``
hyfei1123 2008-06-04
  • 打赏
  • 举报
回复
function check(strInput)
{
document.getElementById('txt').innerHTML=strInput.value.split(/\s+/).length;
}


测试通过 over
familyX 2008-06-03
  • 打赏
  • 举报
回复
给楼主一个正确的

<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>
hyfei1123 2008-06-03
  • 打赏
  • 举报
回复
高手呢 快帮帮忙吧 谢谢了
hyfei1123 2008-06-03
  • 打赏
  • 举报
回复
楼上的不行 还是死
fytx0113 2008-06-03
  • 打赏
  • 举报
回复
document.getElementById('txt').innerText = num/2;
改为:document.getElementById('txt').innerHTML = num/2; 
innerText在firefox中无效
jamo 2008-06-02
  • 打赏
  • 举报
回复
go get Firefox addon "Firebug"
hyfei1123 2008-06-02
  • 打赏
  • 举报
回复
楼主改的不对吧
mingxuan3000 2008-06-02
  • 打赏
  • 举报
回复
if(navigator.appName.indexOf("Explorer") >-1)
{
   document.getElementById('txt').value= num/2; 
   }
   else
   {
   document.getElementById('txt').value= num/2;   
   }

}
fcoolx 2008-06-02
  • 打赏
  • 举报
回复
js不兼容

87,919

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧