<script>
function editTab()
{
var code, sel, tmp, r
var tabs=""
event.returnValue = false
sel =event.srcElement.document.selection.createRange()
r = event.srcElement.createTextRange()
function reportError(msg,url,line) {
var str = "You have found an error as below: \n\n";
str += "Err: " + msg + " on line: " + line;
alert(str);
return true;
}
window.onerror = reportError;
document.onkeydown = function() {
if(event.ctrlKey){
switch(event.keyCode) {
case 82: //r
runcode();
break;
case 83: //s
savecode();
break;
case 71: //g
goto(prompt('Please input the line number', '1'));
break;
case 65: //a
document.execCommand("SelectAll");
break;
case 67: //c
document.execCommand("Copy");
break;
case 88: //x
document.execCommand("Cut");
break;
case 86: //v
document.execCommand("Paste");
break;
case 90: //z
document.execCommand("Undo");
break;
case 89: //y
document.execCommand("Redo");
break;
default:
break;
}
event.keyCode = 0;
event.returnValue = false;
}
return;
}
function show_ln(){
var txt_ln = document.getElementById('txt_ln');
var txt_main = document.getElementById('txt_main');
txt_ln.scrollTop = txt_main.scrollTop;
while(txt_ln.scrollTop != txt_main.scrollTop) {
txt_ln.value += (i++) + '\n';
txt_ln.scrollTop = txt_main.scrollTop;
}
return;
}
function editTab(){
var code, sel, tmp, r
var tabs=''
event.returnValue = false
sel =event.srcElement.document.selection.createRange()
r = event.srcElement.createTextRange()
function runcode() {
var str = document.getElementById("txt_main").value;
var code_win = window.open('about:blank');
code_win.document.open();
code_win.document.writeln("<script>");
code_win.document.writeln("function reportError(msg,url,line){\nline-=14;\nvar str='You have found an error as below: \\n\\n';\nstr+='Err: '+msg+' on line: '+(line);\nalert(str);\nopener.goto(line);\nopener.focus();\nwindow.onerror=null;\nsetTimeout('self.close()',10);\nreturn true;\n}");
code_win.document.writeln("window.onerror = reportError;");
code_win.document.writeln("<\/script>");
code_win.document.writeln(str);
code_win.document.close();
return;
}
function savecode() {
var str = document.getElementById("txt_main").value;
var code_win = window.open('about:blank','_blank','top=10000');
code_win.document.open();
code_win.document.writeln(str);
code_win.document.close();
code_win.document.execCommand('saveas','','code.html');
code_win.close();
return;
}
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 method="post" name=test onSubmit="return checkdata()" action="">
<TEXTAREA onkeydown="return changebyte1(document.test.icqcontent.value,198)" onkeyup="return changebyte1(document.test.icqcontent.value,198)" name=icqcontent cols=40 rows="3"></TEXTAREA>
<SPAN id=byte1><SCRIPT language=JavaScript>changebyte1(document.test.icqcontent.value,198);</SCRIPT></SPAN>
</form>
判断填写字数的限制
<script language=javascript>
function gbcount(message,total,used,remain)
{
var max;
max = total.value;
if(message.value.length > max){
message.value = message.value.substring(0,max);
used.value = max;
remain.value = 0;
alert('留言不能超过规定的字数!');
}
else{
used.value = message.value.length;
remain.value = max - used.value;
}
}
</script>