我正在使用Jquery字符计数器,我在IE中遇到此错误。 “SCRIPT438:对象不支持属性或方法'jqEasyCounter'”Firefox和Chrome运行良好。
我可以在代码中更改哪些内容以确保它适用于IE?
由于
以下Javascript代码:
(
function(a)
{
a.fn.extend({jqEasyCounter:function(b)
{
return this.each(function()
{
var f=a(this),e=a.extend({
maxChars:100,maxCharsWarning:80,msgFontSize:"12px",
msgFontColor:"#000000",msgFontFamily:"Arial",
msgTextAlign:"right",msgWarningColor:"#F00",msgAppendMethod:"insertAfter"},b);
if(e.maxChars<=0)
{
return
}
var d=a('<div class="jqEasyCounterMsg"> </div>');
var c={"font-size":e.msgFontSize,"font-family":e.msgFontFamily,
color:e.msgFontColor,"text-align":e.msgTextAlign,width:f.width(),opacity:0};
d.css(c);
d[e.msgAppendMethod](f);
f.bind("keydown keyup keypress",g).bind("focus paste",function()
{
setTimeout(g,10)
}).bind("blur",function()
{
d.stop().fadeTo("fast",0);
return false
});
function g() {
var i=f.val(),h=0;
for (var x = 0; x < i.length; x++) {
if (i.codePointAt(x) < 128) {
h = h + 1;
} else {
h = h + 2;
}
}
if(h>=e.maxChars){
i=i.substring(0,e.maxChars)
}
if(h>e.maxChars){
var j=f.scrollTop();
f.val(i.substring(0,e.maxChars));
f.scrollTop(j)
}
if(h>=e.maxCharsWarning){
d.css({color:e.msgWarningColor})
}
else {
d.css({color:e.msgFontColor})
}
d.html("Characters: "+h+"/"+e.maxChars);
d.stop().fadeTo("fast",1)
}
})
}
})
})(jQuery);
实际页面上的Javascript:
<script type="text/javascript">
function charCount(){
$('.countable1').jqEasyCounter({
'maxChars': 250,
'maxCharsWarning': 250
});
}
</script>