在textarea字段中更改字体和字体大小 [英] Changing the Font and font Size in a textarea field
本文介绍了在textarea字段中更改字体和字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码示例:
<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>
如何更改textarea中的字体和字体大小?
How do I change the font and font size in the textarea?
推荐答案
使用 CSS 定义样式元素 textarea
。例如:
Use CSS to define a style for the textarea
element. For example:
textarea {
font-size: 20pt;
font-family: Arial;
}
请注意,有三种方法添加CSS到您的网站 - 您可以使用外部样式表,内部样式表或内联样式(或其组合)。
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
.
这篇关于在textarea字段中更改字体和字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文