[英]Changing the Font and font Size in a textarea field
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? 如何更改textarea中的字体和字体大小?
Use CSS to define a style for the textarea
element. 使用CSS为
textarea
元素定义样式。 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). 请注意,有三种方法可以将CSS添加到您的网站 - 您可以使用外部样式表,内部样式表或内联样式(或其组合)。
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
. 有关样式
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. 使用Iframe并初始化它以在页面加载时运行并隐藏textarea ...如果你想制作一个WYSIWYG编辑器,这会有所帮助。
html page: onLoad="iFrame()" html页面:onLoad =“iFrame()”
js page: function iFrame(){ name.document.designMode = 'on'; js page:function iFrame(){name.document.designMode ='on'; name.document.execCommand('fontName',false,"verdana");
name.document.execCommand( '的fontName',假 “宋体”);
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.