網頁:超級實用的幾種表單校正效果收集

來源:互聯網
上載者:User
網頁

只能是寫限定的東西

程式碼:

ENTER鍵可以讓游標移到下一個輸入框

<input >
// Coded by windy_sk <windy_sk@126.com> 20040205

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()

switch (event.keyCode){
case (8) :
if (!(sel.getClientRects().length > 1)){
event.returnValue = true
return
}
code = sel.text
tmp = sel.duplicate()
tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
// 出錯檢驗代碼~~~~~~
if(sel.parentElement() != tmp.parentElement()) return;
sel.setEndPoint('startToStart', tmp)
sel.text = sel.text.replace(/^\t/gm, '')
code = code.replace(/^\t/gm, '').replace(/\r\n/g, '\r')
r.findText(code)
r.select()
break
case (9) :
if (sel.getClientRects().length > 1){
code = sel.text
tmp = sel.duplicate()
tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
// 出錯檢驗代碼~~~~~~
if(sel.parentElement() != tmp.parentElement()) return;
sel.setEndPoint('startToStart', tmp)
sel.text = '\t'+sel.text.replace(/\r\n/g, '\r\t')
code = code.replace(/\r\n/g, '\r\t')
r.findText(code)
r.select()
}else{
sel.text = '\t'
sel.select()
}
break
case (13) :
tmp = sel.duplicate()
tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
// 出錯檢驗代碼~~~~~~
if(sel.parentElement() != tmp.parentElement()) return;
tmp.setEndPoint('endToEnd', sel)
for (var i=0; tmp.text.match(/^[\t]+/g) && i<tmp.text.match(/^[\t]+/g)[0].length; i++) tabs += '\t'
sel.text = '\r\n'+tabs
sel.select()
break
default :
event.returnValue = true
break;
}
return;
}


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 goto(ln) {
if(!/^\d+$/.test(ln)) return;
var obj = document.getElementById('txt_main');
var rng = obj.createTextRange();
var arr = obj.value.replace(/\r/, '').split(/\n/);
if(ln>arr.length) ln = arr.length;
var str_tmp = '';
for(var i=0; i<ln-1; i++) {
str_tmp += arr[i];
}
rng.moveStart('character',str_tmp.length+1);
str_tmp = '';
for(i=ln; i<arr.length; i++) {
str_tmp += arr[i];
}
rng.moveEnd('character',-str_tmp.length);
rng.select();
return;
}

window.onload = function() {document.getElementById('txt_main').value = '<script>\nalert(')\n<\/script>';}
</script>
<BODY>
<table width='600' class='list' border='1' bgcolor='#eeeeee' bordercolorlight='#000000' bordercolordark='#FFFFFF' cellpadding='0' cellspacing='0'>
<tr bgcolor='#cccccc'>
<td colspan='2' height='20' align='center'><b>Debug Textarea</b></td>
</tr>
<tr>
<td colspan='2'>
<table width='95%' border='0' align='center' >
<tr>
<td align='center'><br />
<textarea id='txt_ln' name='content' rows='10' style='width:40px;overflow:hidden;height:200px;border-right:0px;text-align:right;line-height:14px' onselectstart='this.nextSibling.focus();return false' readonly></textarea><textarea id='txt_main' name='content' rows='10' cols='80' onkeydown=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain); onkeyup=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain);></textarea>
最多字數:<INPUT disabled maxLength=4 name=total size=3 value=20>
已用字數:<INPUT disabled maxLength=4 name=used size=3 value=0>
剩餘字數:<INPUT disabled maxLength=4 name=remain size=3>
</form>



相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。