Показать сообщение отдельно
Старый 29.07.2004, 06:19     # 10
aceofext
Member
 
Регистрация: 27.08.2002
Адрес: Канада
Пол: Male
Сообщения: 343

aceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуруaceofext Гуру
Уф. Есть решение. Правда наверное только для IE. Поддерживает Copy/Paste.

Создаётся след. HTC (HTML Component) файл:
maxlength.htc
Код:
<PUBLIC:COMPONENT id="bhvMaxlength" urn="maf:Maxlength">
	<PUBLIC:PROPERTY name="maxLength" />
	<PUBLIC:ATTACH event="onkeypress" handler="doKeypress" />
	<PUBLIC:ATTACH event="onbeforepaste" handler="doBeforePaste" />
	<PUBLIC:ATTACH event="onpaste" handler="doPaste" />

	<SCRIPT language="JScript">
	// Keep user from entering more than maxLength characters
	function doKeypress(){
	     if(maxLength && value.length > maxLength-1){
	          event.returnValue = false;
	          maxLength = parseInt(maxLength);
	     }
	}
	// Cancel default behavior
	function doBeforePaste(){
	     if(maxLength)
	          event.returnValue = false;
	}
	// Cancel default behavior and create a new paste routine
	function doPaste(){
	     if(maxLength){
	          event.returnValue = false;
	          maxLength = parseInt(maxLength);
	          var oTR = element.document.selection.createRange();
	          var iInsertLength = maxLength - value.length + oTR.text.length;
	          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
	          oTR.text = sData;
	     }
	}
	</SCRIPT>
</PUBLIC:COMPONENT>
Затем в HTML файле пишется следущая весчь:
Код:
<textarea maxlength="255" style="behavior: url(maxlength.htc)"></textarea>
Понятно, что можно сделать тоже самое и без HTC файла. Но с ним красиво

Последний раз редактировалось aceofext; 29.07.2004 в 06:22.
aceofext вне форума