如何将此文本框中文字属性在另一文本框中显示?
发布网友
发布时间:2022-06-08 11:28
我来回答
共1个回答
热心网友
时间:2023-11-23 00:17
包括字体和大小的程序:
<SCRIPT LANGUAGE="JavaScript">
var fs, ff;
fs = "12";
ff = "宋体";
function changeSize(obj){
document.all.modes.style.fontSize = obj.value;
fs = obj.value;
}
function changeFont(obj){
document.all.modes.style.fontFamily = obj.value;
ff = obj.value;
}
function toDIV() {
var oHid = document.getElementById("vvv");
var oDIV = document.getElementById("yhu");
var oTxt = document.getElementById("modes");
var fstr = "<span style='font-size:" + fs + "px; font-family:" + ff + "'>";
oHid.value = fstr + oTxt.value + "</span>";
oDIV.innerHTML = oHid.value;
}
</SCRIPT>
<select name="select" onChange="changeFont(this)" ID="Select1">
<option value="黑体">黑体</option>
<option value="宋体" selected>宋体</option>
</select>
<select name="select2" onChange="changeSize(this)" ID="Select2">
<option value="9">五号</option>
<option value="12" selected>四号</option>
</select>
<textarea name="modes" cols="52" rows="6" style="width: 500px;height: 300px" ID="modes" onkeyup="toDIV()">
稍微修改了一下,下面的代码效果应该很清楚了:
<SCRIPT LANGUAGE="JavaScript">
var fs, ff, fc;
fs = "9";
ff = "宋体";
fc = "black";
function changeSize(obj){
document.all.modes.style.fontSize = obj.value;
fs = obj.value;
toDIV()
}
function changeFont(obj){
document.all.modes.style.fontFamily = obj.value;
ff = obj.value;
toDIV()
}
function changeColor(obj){
document.all.modes.style.color = obj.value;
fc = obj.value;
toDIV()
}
function toDIV() {
var oHid = document.getElementById("vvv");
var oDIV = document.getElementById("yhu");
var oTxt = document.getElementById("modes");
var fstr = "<span style='color:" + fc + ";font-size:" + fs + "px; font-family:" + ff + "'>";
oHid.value = fstr + oTxt.value + "</span>";
oDIV.innerHTML = oHid.value;
}
</SCRIPT>
<select name="select" onChange="changeFont(this)" ID="Select1">
<option value="黑体">黑体</option>
<option value="宋体" selected>宋体</option>
</select>
<select name="select" onChange="changeColor(this)" ID="Select3">
<option value="red">红色</option>
<option value="black" selected>黑色</option>
<option value="blue">蓝色</option>
</select>
<select name="select2" onChange="changeSize(this)" ID="Select2">
<option value="9" selected>五号</option>
<option value="12">四号</option>
<option value="16">三号</option>
</select>
<textarea name="modes" cols="52" rows="6" style="width: 500px;height: 300px; font-size:9px; font-family:宋体" ID="modes" onkeyup="toDIV()">