WRAP ein-/ausschalten
Eduard Gode
- javascript
0 Cybaer
Hi,
hier findet Ihr eine Funktion setWrap(), mit der man
das wrap-Attribut ein und umschalten kann.
<html>
<head>
<title>textarea Wrap</title>
<script language="JavaScript">
<!--
function setWrap(field,wrap) {
//field.setAttribute( 'wrap', wrap, false );
var value = field.value;
// quote special chars: '<' '>' '&'
value = value.replace(/&/g,'&');
value = value.replace(/</g,'<');
value = value.replace(/>/g,'>');
var par = field.parentNode;
var tag = par.innerHTML;
var rest = '';
// we have to delete the old wrap attribute just out of the tag attribute and not from the content.
// so split the innerHTML code to determine the tag and recompose the full html code manualy.
if ( tag.match( /^(\s*<[^>]*>)/m ) ) {
tag = RegExp.$1;
rest = value + '</textarea>';
}
var tag = tag.replace( / wrap="?\w+"?/i, '' );
par.innerHTML = tag.replace( /<textarea/i, '<textarea wrap="'+wrap+'"' ) + rest;
}
// -->
</script>
</head>
<body>
<h1>textarea Wrap</h1>
<form name="formular">
<textarea name="text" cols="40" rows="10">Text Text wrap="any" Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text</textarea>
</form>
Press on links below to switch wrap Attribute of the textarea:<br>
<a href="javascript:setWrap(document.formular.text,'off')">Off</a><br>
<a href="javascript:setWrap(document.formular.text,'virtual')">Virtual</a>
<p>
Function tested on Linux Mozilla: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113<br>
</p>
<hr>
<address><a href="mailto:eduard@weitblick.net">Eduard Gode</a></address>
<!-- Created: Wed Oct 13 15:24:02 CEST 2004 -->
<!-- hhmts start -->
Last modified: Wed Oct 13 17:53:47 CEST 2004
<!-- hhmts end -->
</body>
</html>
Hi,
hier findet Ihr eine Funktion setWrap(), mit der man
das wrap-Attribut ein und umschalten kann.
Jo, super!
Und ein Extra-Dank für deine Aufmerksamkeit! :-)))
Function tested on Linux Mozilla: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113<br>
Auch auf IE 5.5 und 6.0 funktioniert es. :-)
Gruß, Cybaer