Javascript 如何使用html输入标记设置文本区域中文本的颜色
HTMLJavascript 如何使用html输入标记设置文本区域中文本的颜色,javascript,html,css,function,textarea,Javascript,Html,Css,Function,Textarea,HTML <form name="myform"> Select Color : <input type="color" onClick="Color()"> </form> <textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ..."></textarea> <form name="my
<form name="myform">
Select Color : <input type="color" onClick="Color()">
</form>
<textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ..."></textarea>
<form name="myform">
Select Color : <input type="color" onkeydown="Color(this.value)">
</form>
<textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ..."></textarea>
我做错了什么
以同样的方式,我将如何为文本区域中的特定单词设置特定字体(族字体) 使用
onkeyup
而不是onclick
HTML
<form name="myform">
Select Color : <input type="color" onClick="Color()">
</form>
<textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ..."></textarea>
<form name="myform">
Select Color : <input type="color" onkeydown="Color(this.value)">
</form>
<textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ..."></textarea>
您可以这样做,为文本应用选定的颜色
<input type="color" onClick="Color(this)">
function Color(cthis){
document.getElementById("myTextArea").style.color = cthis.value
}
对于输入类型颜色,使用
onchange
事件是有意义的。它将根据您的需要工作:
<input type="color" onchange="Color(this)">
演示:这样做:
<input type="color" id="color"/>
没有OnClick之类的东西让jQuery来做
问题上没有jQuery标记看起来他对Javascript不太熟悉,因此jQuery将是一个不错的选择,因为它会去掉一些东西,例如OnClick或处理参数。他对Javascript不熟悉,所以让他先了解一下。这是一个跳跃2步的步骤。如果问题中包含了标签。但对于初学者来说,如果不懂基本的javascript,就很难理解jQuery(即使很简单)
function Color(obj) {
document.getElementById("myTextArea").style.color = obj.value;
}
<input type="color" id="color"/>
$("#color").change(function(){
var clr = $(this).val();
$("#myTextArea").css("color",clr);
});