function SetTextAreaMaxLength(controlId,length)
{
// TextArea 的JScript 檔案
// 阻止使用者輸入超過maxLength 的字元
Keyfunction doo( 🎜>maxLength = 長度;
值=control.value;
if(maxLength && value.length > maxLength-1){
event.returnValue = false;
Lmaxth = parseInt(Lmaxth));
}
}
// 取消預設行為
function doBeforePaste(control,length){
maxLength = length;
if(maxLength)
maxLength = length;
if(maxLength)
{
event> returnValue = false;
}
}
// 取消預設行為並建立新的貼上程式
function doPaste(control,length){
maxLength = length
值= control.value;
if(maxLength){
event.returnValue = false;
maxLength = parseInt(maxLength);
var oTR = control.document.selection.createRange()
var iInsertLength = maxLength - value.length oTR.text.length;
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
oTR.text = sData; }
}
函數doDragenter(control,length)
{
maxLength = 長度;
值=control.value;
if(maxLength){
event.returnValue = false;
}
}
函數addEvent(elm, evType, fn, useCapture)
{
if (elm.addEventListener)
{
elm..add fn,使用捕獲);
返回真;
}
else if (elm.attachEvent)
{
var r = elm.attachEvent('on' evType, fn);
回傳r;
}
else {
elm['on' evType] = fn;
}
}
函數AttacheventTextAreaBeforePaste(obj,length)
函數AttacheventTextAreaBeforePaste(obj,length)
{
return function()
{
doBeforePaste(obj,length)
}
}
function AttacheventTextAreaPaste(obj,length)
{
{
doPaste(obj,length)
}
}
function AttacheventTextAreaKeyPress(obj,長度)
{
回傳函數()
{
length)
}
}
函數AttacheventTextAreaDragEnter(obj,length)
{
return function()
{
doDragenter(obj,length); 🎜>}
var obj = document.getElementById(controlId);
addEvent(obj,'按鍵',AttacheventTextAreaKeyPress(obj,length),null);
obj,length),null);
addEvent(obj,'paste',AttacheventTextAreaPaste(obj,length),null);
addEvent(obj,'dragenter',AttacheventTextAreaDragEnter(objull,length),nn);
}
function SetTextAreaMaxLength(controlId,length)
{
// TextArea 的JScript 檔案
// 阻止使用者輸入超過maxLength 的字元
function doo
maxLength = 長度;
值=control.value;
if(maxLength && value.length > maxLength-1){
event.returnValue = false;
Lmaxth = parseInt(max3) ;
}
}
// 取消預設行為
function doBeforePaste(control,length){
maxLength = length;
if(maxLength)
maxLength = length;
if(maxLength)
{
.returnValue = false;
}
}
// 取消預設行為並建立新的貼上程式
function doPaste(control,length){
maxLength = length;
值
值=control.value;
if(maxLength){
event.returnValue = false;
maxLength = parseInt(maxLength);
var oTR = control.document.selection.createRange()
var oTR = control.document.selection.createRange() var iInsertLength = maxLength - value.length oTR.text.length;
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
oTR.text = sData; >}
}
函數doDragenter(control,length)
{
maxLength = 長度;
值=control.value;
if(maxLength){
event.return = false;
}
}
函數addEvent(elm, evType, fn, useCapture)
{
if (elm.addEventListener)
{
elm.Type , fn,使用捕獲);
返回真;
}
else if (elm.attachEvent)
{
var r = elm.attachEvent('on' evType, fn);
返回r;
}
else {
elm['on' evType] = fn;
}
}
函數AttacheventTextAreaBeforePaste(obj,length) { 🎜>return function()
{
doBeforePaste(obj,length)
}
}
function AttacheventTextAreaPaste(obj,length)
{ function🎜> >{
doPaste(obj,length)
}
}
function AttacheventTextAreaKeyPress(obj,長度)
{
回傳函數()
{
,length)
}
}
函數AttacheventTextAreaDragEnter(obj,length)
{
return function()
{
doragenter(obj,lengenter(obj,lengenter);
}
var obj = document.getElementById(controlId);
addEvent(obj,'keypress',AttacheventTextAreaKeyPress(obj,length),null);
>Event(obofm-Badm-Ladm-Bunun區,B.Badbeat,Badperpaste(Bunoo-Baduno5,Badm); (obj,length),null);
addEvent(obj,'paste',AttacheventTextAreaPaste(obj,length),null);
addEvent(obj,'dragenter',AttacheventTextAreaDragEnter(objull,length),nacheventText ;
}
----------------------------------------------- ------------------------------------------------
HTML程式碼
複製程式碼 程式碼如下:
TextMode="MultiLine" Height="113px" MaxLength="10">