不同颜色的文本(javascript)(HTML) [英] Text with different colors (javascript)(HTML)
问题描述
我通过听按键事件并使用样式生成随机颜色的跨度来制作不同颜色的文本。我觉得有很多开销可以做得更好吗?。请帮助我
codepen的链接如下:
Codepen
我尝试过:
我通过听按键事件并使用样式生成随机颜色的跨度来制作不同颜色的文本。我觉得有很多开销可以做得更好吗?。请帮助我
指向codepen的链接如下:
Codepen
I made text with different colors by listening to keypress events and generating a span with random colors using style.I feel there is alot of overhead how can this be done better?.please help me
the link to codepen is below:
Codepen
What I have tried:
I made text with different colors by listening to keypress events and generating a span with random colors using style.I feel there is alot of overhead how can this be done better?.please help me
the link to codepen is below:
Codepen
推荐答案
尝试
try
(< span class =code-sdkkeyword> document )。on( keypress, function (e){
if (e.keyCode == 32 )
{
(document).on("keypress", function (e) { if(e.keyCode == 32) {
( .editable)。append( < span> + + < /跨度> 中跨度>);
}
else if (e.keyCode == 8 )
{
(".editable").append("<span>"+" "+"</span>"); } else if(e.keyCode == 8) {
这篇关于不同颜色的文本(javascript)(HTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!