使用JavaScript计数textarew中的字符在firefox中不起作用!为什么? [英] using javascript to count chars in a textarew is not working in firefox !! why?
本文介绍了使用JavaScript计数textarew中的字符在firefox中不起作用!为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想尝试计算字符和单词,并确定其是否在常规textarea控件(usig javascript)中使用heb或eng,但是在firefox中这些都不起作用,有人可以帮助我吗?
我的代码:
hello im trying to count chars ans words and determine if its heb or eng in a regular textarea control, usig javascript, but none of this works in firefox, can someone please help me?
my code :
<script type="text/javascript">
function langChk()
{
var str = new String(document.smsform.txt2.innerText.toString());
var i = 0;
var cnt = str.length;
if(cnt == 0)
{
document.all('msgCounter').innerHTML = "0"
document.all('chrCounter').innerHTML = "0"
}
for(i=0 ; i < cnt ; i++) // will not start unless cnt > 0
{
var ch = parseInt(str.charCodeAt(i));
if(ch >= 1488 && ch <=1514) //chk 4 heb
{
counter(1,cnt);
break;
}
else
counter(2,cnt);
}
}
function counter(method,cnt) //accepts lang method and calc num of msgs
{
switch(method)
{
case 1 :
if(cnt > 0 && cnt <= 70)
document.all('msgCounter').innerHTML = "1";
if(cnt > 70 && cnt <= 134)
document.all('msgCounter').innerHTML = "2";
if(cnt > 134 && cnt <= 201
</script>
有人可以在这里指出问题吗? (我知道代码块在中间被切掉了,好)
noam
can anyone point on a problem here guys ?? (i know the code block is cut in the middle, ok)
noam
推荐答案
请参见 http://simonwillison.net/2003/Aug/11/documentAll/ [ ^ ](以及许多其他内容)来说明为什么不应该使用document.all
来代替使用document.getElementByID
的原因.
document.all
是过时的IE4怪胎.
干杯,
彼得
See http://simonwillison.net/2003/Aug/11/documentAll/[^] (and many others) for why you shouldn''t usedocument.all
Usedocument.getElementByID
instead.
document.all
is an obsolete IE4 monstrosity.
Cheers,
Peter
第一个引起我注意的问题是使用属性innerText
. W3C的官方资源为textContent
;与IE不同,Mozilla倾向于支持这些标准.请参阅:
https://developer.mozilla.org/En/DOM/Node.textContent [ ^ ].
一种跨浏览器兼容性的技巧是通过以下方式同时使用两者:
First problem which caught my eyes was using the propertyinnerText
. The official W3C property istextContent
; and Mozilla tends to support the standards, unlike IE. Please see:
https://developer.mozilla.org/En/DOM/Node.textContent[^].
One cross-browser compatibility trick is using both in the following way:
myElement = document.smsform.txt2;
str = myElement.textContent || myElement.innerText;
这篇关于使用JavaScript计数textarew中的字符在firefox中不起作用!为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文