<script>
var ns6=document.getElementById&&!document.allfunction restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
function displaylimit(theform,thelimit){
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}</script></head><body><form name="sampleform"><input type="text" name="george" size=20><br>
<script>
displaylimit("document.sampleform.george",115)
</script>
<p>
<textarea name="john" cols=25 rows=15></textarea><br>
<script>
displaylimit("document.sampleform.john",110)
</script></form></body>
</html>
var ns6=document.getElementById&&!document.allfunction restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
function displaylimit(theform,thelimit){
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}</script></head><body><form name="sampleform"><input type="text" name="george" size=20><br>
<script>
displaylimit("document.sampleform.george",115)
</script>
<p>
<textarea name="john" cols=25 rows=15></textarea><br>
<script>
displaylimit("document.sampleform.john",110)
</script></form></body>
</html>
解决方案 »
- js 正则表达式 求助
- 如何用代码判断IE是32位还是64位的?
- yui框架 谁用过 哪位大哥能给点 学习资料吗
- 求一段代码,能够实现多个镜像站点之间互相测速,并且选择最快的一个镜像访问!
- document.write 使firefox 假死
- 关于js文件中引用另一个js文件函数的问题
- 百度面试题,不点击a标签,但是a有点击后的标记
- 50分。求解向父页面传递参数的问题
- 怎么动态设置表格的边宽呢?
- 急!!帮我找找错
- 这样初始化数组不行吗???var people = new Array(2);people = {"姓名", "性别"};
- 使用javascript是否可以判断cookie是否存在?
<HEAD>
<SCRIPT language=JavaScript>
function strlength(str){
var l=str.length;
var n=l
for (var i=0;i<l;i++)
{
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
}
return n
}
function changebyte(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte").innerText="»¹¿ÉÒÔÊäÈë"+(length-l)+"×Ö½Ú"
}
else
{
alert('ÊäÈë×Ö½ÚÊý³¬³ö·¶Î§');
document.all("byte").innerText="ÊäÈë×Ö½ÚÊý³¬³ö·¶Î§"
return false;
}
return true
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=test onsubmit="return checkdata()" action="" method=post>
<TEXTAREA onkeydown="return changebyte(document.test.icqcontent.value,20)" onkeyup="return changebyte(document.test.icqcontent.value,20)" name=icqcontent rows=3 cols=40>
</TEXTAREA>
<SPAN id=byte style="font-size:12px">
<SCRIPT language=JavaScript>
changebyte1(document.test.icqcontent.value,20);
</SCRIPT>
</SPAN></FORM></BODY></HTML>
<HTML>
<HEAD>
<SCRIPT language=JavaScript>
function strlength(str){
var l=str.length;
var n=l
for (var i=0;i<l;i++)
{
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
}
return n
}
function changebyte(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte").innerText="还可以输入"+(length-l)+"字节"
}
else
{
alert('输入字节数超出范围');
document.all("byte").innerText="输入字节数超出范围"
return false;
}
return true
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=test onsubmit="return checkdata()" action="" method=post>
<TEXTAREA onkeydown="return changebyte(document.test.icqcontent.value,20)" onkeyup="return changebyte(document.test.icqcontent.value,20)" name=icqcontent rows=3 cols=40>
</TEXTAREA>
<SPAN id=byte style="font-size:12px">
<SCRIPT language=JavaScript>
changebyte1(document.test.icqcontent.value,20);
</SCRIPT>
</SPAN></FORM></BODY></HTML>
if (l>=length) {//判断如果长度l超过给定值length 则封键盘
window.event.cancelBuuble=true;
window.event.returnValue=false;
}
<!-- saved from url=(0046)http://www.blueidea.com/user/poorfish/form.htm -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<SCRIPT language=JavaScript>
function strlength(str){
var l=str.length;
var n=l
for (var i=0;i<l;i++)
{
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
}
return n
}function changebyte(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte").innerText="还可以输入"+(length-l)+"字节"
}
else
{
document.all("byte").innerText="输入字节数超出范围"
}
return true
}function changebyte1(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte1").innerText="还可以输入"+(length-l)+"字节"
}
else
{
document.all("byte1").innerText="输入字节数超出范围"
}
return true
}function changebyte2(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte2").innerText="还可以输入"+(length-l)+"字节"
}
else
{
document.all("byte2").innerText="输入字节数超出范围"
}
return true
}
</SCRIPT><FORM name=test onsubmit="return checkdata()" action="" method=post>
<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY><TEXTAREA onkeydown="return changebyte1(document.test.icqcontent.value,20)" onkeyup="return changebyte1(document.test.icqcontent.value,20)" name=icqcontent rows=3 cols=40></TEXTAREA>
<SPAN id=byte1 style="font-size:12px">
<SCRIPT
language=JavaScript>changebyte1(document.test.icqcontent.value,20);</SCRIPT>
</SPAN></FORM></BODY></HTML>
<!-- saved from url=(0046)http://www.blueidea.com/user/poorfish/form.htm -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<SCRIPT language=JavaScript>
function strlength(str){
var l=str.length;
var n=l
for (var i=0;i<l;i++)
{
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
}
return n
}function changebyte(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte").innerText="»¹¿ÉÒÔÊäÈë"+(length-l)+"×Ö½Ú"
}
else
{
document.all("byte").innerText="ÊäÈë×Ö½ÚÊý³¬³ö·¶Î§"
}
return true
}function changebyte1(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte1").innerText="»¹¿ÉÒÔÊäÈë"+(length-l)+"×Ö½Ú"
}
else
{
document.all("byte1").innerText="ÊäÈë×Ö½ÚÊý³¬³ö·¶Î§"
}
return true
}function changebyte2(value,length){
var l=strlength(value)
if (l<=length) {
if (document.all!=null) document.all("byte2").innerText="»¹¿ÉÒÔÊäÈë"+(length-l)+"×Ö½Ú"
}
else
{
document.all("byte2").innerText="ÊäÈë×Ö½ÚÊý³¬³ö·¶Î§"
}
return true
}
</SCRIPT><FORM name=test onsubmit="return checkdata()" action="" method=post>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY><TEXTAREA onkeydown="return changebyte1(document.test.icqcontent.value,20)" onkeyup="return changebyte1(document.test.icqcontent.value,20)" name=icqcontent rows=3 cols=40></TEXTAREA>
<SPAN id=byte1 style="font-size:12px">
<SCRIPT
language=JavaScript>changebyte1(document.test.icqcontent.value,20);</SCRIPT>
</SPAN></FORM></BODY></HTML>