支持tab键的文本编辑框
<TEXTAREA NAME="ice" id='ice' ROWS="50" COLS="100" onkeydown='testTab()'></TEXTAREA>
<SCRIPT LANGUAGE="JavaScript">
<!--
function testTab()
{
var sel = document.selection.createRange();
var mytext= sel.text;
var i,j,k;
if (event.shiftKey && event.keyCode == 9)
{
arr=mytext.split(String.fromCharCode(13,10))
mytext=""
for(k=0;k<arr.length;k++)
{
for (j=1; j<=4;j++)
{
if(arr[k].substr(0,1)=="\u0020")
{
arr[k]=arr[k].slice(1)
}
}
mytext += arr[k] + ((k==(arr.length-1))? "" : String.fromCharCode(13,10));
}
with(sel){
sel.text = mytext;
collapse(true)
moveEnd("character",0)
moveStart("character",(mytext.length ) * -1)
select()
}
window.event.cancelBubble = true;
event.returnValue = false;
return;
}
if (event.keyCode == 9)
{
arr=mytext.split(String.fromCharCode(13,10))
mytext=""
for(j=0;j<arr.length;j++)
{
mytext += "\u0020\u0020\u0020\u0020" + arr[j] + ((j==(arr.length-1))? "" : String.fromCharCode(13,10));
}
with(sel){
sel.text = mytext;
collapse(true)
moveEnd("character",0)
moveStart("character",(mytext.length -4) * -1)
select()
}
window.event.cancelBubble = true;
event.returnValue = false;
return;
}
}
//-->
</SCRIPT>
<TEXTAREA NAME="ice" id='ice' ROWS="50" COLS="100" onkeydown='testTab()'></TEXTAREA>
<SCRIPT LANGUAGE="JavaScript">
<!--
function testTab()
{
var sel = document.selection.createRange();
var mytext= sel.text;
var i,j,k;
if (event.shiftKey && event.keyCode == 9)
{
arr=mytext.split(String.fromCharCode(13,10))
mytext=""
for(k=0;k<arr.length;k++)
{
for (j=1; j<=4;j++)
{
if(arr[k].substr(0,1)=="\u0020")
{
arr[k]=arr[k].slice(1)
}
}
mytext += arr[k] + ((k==(arr.length-1))? "" : String.fromCharCode(13,10));
}
with(sel){
sel.text = mytext;
collapse(true)
moveEnd("character",0)
moveStart("character",(mytext.length ) * -1)
select()
}
window.event.cancelBubble = true;
event.returnValue = false;
return;
}
if (event.keyCode == 9)
{
arr=mytext.split(String.fromCharCode(13,10))
mytext=""
for(j=0;j<arr.length;j++)
{
mytext += "\u0020\u0020\u0020\u0020" + arr[j] + ((j==(arr.length-1))? "" : String.fromCharCode(13,10));
}
with(sel){
sel.text = mytext;
collapse(true)
moveEnd("character",0)
moveStart("character",(mytext.length -4) * -1)
select()
}
window.event.cancelBubble = true;
event.returnValue = false;
return;
}
}
//-->
</SCRIPT>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货