admin管理员组文章数量:1193739
Using the following code sample:
<html>
<body>
<script language = "Javascript">
maxL=240;
var bName = navigator.appName;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}
function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
</script>
<font face="Arial" font size="2">
Maximum Number of characters for this text box is 240.</font><br>
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Message" rows=6 wrap="physical" cols=42>
</textarea>
<br>
<font face="Arial" font size="2">
You have <B><SPAN id=myCounter>240</SPAN></B> characters remaining
for your message</font>
</body>
</html>
How do I change the font and font size in the textarea?
Using the following code sample:
<html>
<body>
<script language = "Javascript">
maxL=240;
var bName = navigator.appName;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}
function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
</script>
<font face="Arial" font size="2">
Maximum Number of characters for this text box is 240.</font><br>
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Message" rows=6 wrap="physical" cols=42>
</textarea>
<br>
<font face="Arial" font size="2">
You have <B><SPAN id=myCounter>240</SPAN></B> characters remaining
for your message</font>
</body>
</html>
How do I change the font and font size in the textarea?
Share Improve this question edited Dec 20, 2010 at 14:14 Donut 113k20 gold badges135 silver badges147 bronze badges asked Dec 20, 2010 at 14:13 SquarefingerSquarefinger 1011 gold badge2 silver badges5 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 20Use CSS to define a style for the textarea
element. For example:
textarea {
font-size: 20pt;
font-family: Arial;
}
Note that there are three ways to add CSS to your website -- you can use an external stylesheet, an internal stylesheet, or inline styles (or a combination thereof).
Using an internal stylesheet might look like this:
<head>
<style type="text/css">
textarea {
font-size: 20pt;
font-family: Arial;
}
</style>
</head>
<!-- rest of your code goes here... -->
See here for more information on styling textarea
.
I know this is really old, but I am sure someone could use this information:
use Iframe and initialize it to run when the page is loaded and hide textarea...this helps if you want to make a WYSIWYG editor.
html page: onLoad="iFrame()"
js page: function iFrame(){ name.document.designMode = 'on'; name.document.execCommand('fontName',false,"verdana");
}
本文标签: javascriptChanging the Font and font Size in a textarea fieldStack Overflow
版权声明:本文标题:javascript - Changing the Font and font Size in a textarea field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738465262a2088267.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<font>
tag et al. has been deprecated for ages. Also, checking for Netscape is not really required anymore either... could you tell us what exactly you want to do, maybe someone can get you some modern code to do it ;) – Spiny Norman Commented Dec 20, 2010 at 14:19language
attribute onscript
tags... And then there's the implicit global variable. OMG, and theeval
s. Yeah, this code has slipped through a time machine from 1998. Strongly recommend looking for something more recent. – T.J. Crowder Commented Dec 20, 2010 at 14:19