Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE8中的一个重点领域_Javascript - Fatal编程技术网

Javascript IE8中的一个重点领域

Javascript IE8中的一个重点领域,javascript,Javascript,我有一个JSF2.0应用程序,其中有一个输入文本框,在输入文本框的底部有一个数字字符计数器,我正在通过javascript进行更新 <h:inputTextarea class="myInputTextClass" value="#{bean.text}" style="resize: none;width:445px;" type="text" maxlength="255" cols="60" rows="3" onfocus="countChars($('.myInputTextCl

我有一个JSF2.0应用程序,其中有一个输入文本框,在输入文本框的底部有一个数字字符计数器,我正在通过javascript进行更新

<h:inputTextarea class="myInputTextClass"
value="#{bean.text}"
style="resize: none;width:445px;" type="text"
maxlength="255" cols="60" rows="3"
onfocus="countChars($('.myInputTextClass'),255)"
onkeyup="countChars($('.myInputTextClass'),255);"
onkeydown="countChars($('.myInputTextClass'),255);"
/>

<span id="char_count" style="font-style:italic;margin-left:-14px">255</span>
问题是在输入文本框中键入大约150个字符后,焦点会移回输入文本框的顶部。但是,光标仍如预期的那样位于末尾。

我尝试使用scrollTop位置和焦点,但没有成功。非常感谢您的任何建议


这个问题只发生在IE8中,在forefox中效果很好。

这可能不是您想要的答案,但是这个脚本多年来一直为我服务:

JavaScript:

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve | http://jsmadeeasy.com/ 
http://www.javascriptsource.com/forms/character-counter.html */
function getObject(obj) {
  var theObj;
  if(document.all) {
   if(typeof obj=="string") {
     return document.all(obj);
   } else {
     return obj.style;
   }
 }
 if(document.getElementById) {
   if(typeof obj=="string") {
     return document.getElementById(obj);
   } else {
     return obj.style;
   }
 }
 return null;
}

function toCount(entrance,exit,text,characters) {
 var entranceObj=getObject(entrance);
 var exitObj=getObject(exit);
 var length=characters - entranceObj.value.length;
 if(length <= 0) {
   length=0;
   text='<span class="disable"> '+text+' </span>';
   entranceObj.value=entranceObj.value.substr(0,characters);
 }
 exitObj.innerHTML = text.replace("{CHAR}",length);
}
/*此脚本和更多脚本可在
JavaScript源代码!!http://javascript.internet.com
创作人:史蒂夫|http://jsmadeeasy.com/ 
http://www.javascriptsource.com/forms/character-counter.html */
函数getObject(obj){
var theObj;
如果(全部文件){
如果(对象类型==“字符串”){
返回文件。全部(obj);
}否则{
返回obj.style;
}
}
if(document.getElementById){
如果(对象类型==“字符串”){
返回文档.getElementById(obj);
}否则{
返回obj.style;
}
}
返回null;
}
计数功能(入口、出口、文本、字符){
var enterObj=getObject(入口);
var exitObj=getObject(exit);
变量长度=字符-输入obj.value.length;

如果(长度只是出于好奇,为什么要在3个不同的事件上调用countChars函数?为什么不在向上键时调用它?您只尝试过一个吗?行为是否有任何不同?是的,我需要在聚焦和向上键/向下键时调用它,因为如果用户试图编辑现有的输入文本,则需要立即更新计数,并且在每个字符上都要更新计数。)输入计数需要更新。我只打了一次电话,但运气不好。行下面的注释可以让它工作,但我需要有这个。document.getElementById('char\u count')。innerHTML=count;顺便说一句,不确定这一行是否只是您问题中的html编码,但是如果(计数0){如果您的JS中有小于符号的html实体,则可能会出现问题。。。
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve | http://jsmadeeasy.com/ 
http://www.javascriptsource.com/forms/character-counter.html */
function getObject(obj) {
  var theObj;
  if(document.all) {
   if(typeof obj=="string") {
     return document.all(obj);
   } else {
     return obj.style;
   }
 }
 if(document.getElementById) {
   if(typeof obj=="string") {
     return document.getElementById(obj);
   } else {
     return obj.style;
   }
 }
 return null;
}

function toCount(entrance,exit,text,characters) {
 var entranceObj=getObject(entrance);
 var exitObj=getObject(exit);
 var length=characters - entranceObj.value.length;
 if(length <= 0) {
   length=0;
   text='<span class="disable"> '+text+' </span>';
   entranceObj.value=entranceObj.value.substr(0,characters);
 }
 exitObj.innerHTML = text.replace("{CHAR}",length);
}
(<span id="sBann">'.(255 - strlen($values['synopsis'])).' characters left</span>)<br />
<textarea name="synopsis" id="synopsis" rows="3" cols="70" maxlength="255" wrap="soft" onkeyup="toCount(\'synopsis\',\'sBann\',\'{CHAR} characters left\',255);">'.htmlentities($values['synopsis']).'</textarea>