在HTML控件中查找匹配的内部文本并使用JavaScript更改其格式 [英] Finding matching inner text in HTML controls and changing its format using JavaScript

查看:85
本文介绍了在HTML控件中查找匹配的内部文本并使用JavaScript更改其格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个呈现链接按钮和标签列表的页面。现在我想要一个JavaScript解析这些控件的内部文本,并使用像Google一样匹配的关键字来加强这些控件,同时使用linkbutton及其描述呈现网站列表。

I am generating a page which renders a list of linkbuttons and labels. Now I want a javascript that parses the inner text of these controls and makes bold those with keywords that match like Google does while rendering a list of websites with linkbutton and its description.

我应该如何继续?

推荐答案

链接按钮和标签元素使用 getElementsByTagName ,然后迭代集合并使用 innerHTML 属性访问它们中的内容并与您的关键字进行匹配。然后,匹配元素将 style.fontweight 属性设置为粗体。

To get the collection of link buttons and label elements use getElementsByTagName, then iterate through the collection and use the innerHTML property to access the content within them and match against your keywords. Then for the matching elements set the style.fontweight property to bold.

这篇关于在HTML控件中查找匹配的内部文本并使用JavaScript更改其格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆