English 中文(简体)
用JavaScript创建丰富多彩的文本
原标题:Creating colorful text in JavaScript

我正在尝试编写一个函数,将某个文本打印到<;div id=“1”>标签。

字符串应该用不同的颜色标记某些索引值。

我现在所写的是转到我所拥有的所有索引值,并添加一个<;font color=“color”>标记,然后我使用div1.innerHTML=result添加它

Its a lot of work, and its very complicated. Is there another way that I can create a string object like I ve described without these HTML tags?

如果我能做到这一点,那么我只需要使用<code>div1.appendChild(String)

问题回答

我通常不愿意建议任何人使用他们尚未声称使用的图书馆,但这是一个几乎直接要求图书馆回答的问题:-)

查看Lettering.JS。它的设计完全符合您的描述。它在您的控制下,用<;span>;标记按字母、单词或行(我认为)包装您的文本内容。然后,您可以使用CSS为元素设置样式,或者使用一些JavaScript来操作和设置它为您创建的元素的样式。

if what your looking for is a syntax coloring, you can try this jQuery plugin. http://www.steamdev.com/snippet/





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!