2008-12-09 150 views
2

我有一個應用程序,它允許用戶搜索字符串的多個字段,當他們查看詳細記錄時,他們希望突出顯示所有字符串。突出顯示頁面後的文本

詳細信息表單由標籤和ListView組成,其中大部分位於TabPanels內部(來自AJAX Control Toolkit)。我想避免使用強力手動解析每個值以在顯示之前添加突出顯示標記。

有沒有辦法加載我的表單,然後解析HTML?有沒有其他的方法呢?

回答

5

JavaScript和JQuery如何? http://plugins.jquery.com/project/highlight

我剛試過那個插件,它工作。您可以指定要突出顯示哪些標籤以及哪些字詞。

<script language="javascript" type="text/javascript" src="js/jquery-1.2.6.min.js"></script> 
<script language="javascript" type="text/javascript" src="js/jquery.highlight-2.pack.js"></script> 
<script language="javascript" type="text/javascript"> 
$(document).ready(function() { 
    $('p').each(function() { $.highlight(this, 'LOREM'); }); 
}); 
</script> 
<style type="text/css"> 
    .highlight { background-color: yellow } 
</style> 

.. 
.. 
.. 
    <p> 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi gravida risus elementum tortor. Duis mattis, est et volutpat cursus, mi mi ornare tortor, sed fringilla nibh erat sed eros. In nec orci vel velit scelerisque ultrices. Nunc auctor elit. Proin orci ligula, luctus a, venenatis sit amet, laoreet a, mauris. Suspendisse sem nibh, interdum eu, vestibulum non, semper vel, mauris. In quis leo suscipit risus semper pretium. Cras interdum iaculis dui. Etiam vel ipsum eu sapien dapibus sagittis. Donec lobortis, lectus et placerat euismod, quam dui porttitor sem, sed fermentum eros quam ac ipsum. Ut eu augue. Nullam lacinia dictum neque. Nullam eros. Phasellus sem nisi, feugiat nec, consectetur vel, ullamcorper at, nisl. Aenean quam risus, ullamcorper a, ultricies ut, posuere ac, quam. Vestibulum sed lectus ac orci fermentum viverra. Sed aliquam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. 
    </p> 
+0

http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html是你們網頁上的一些例子。 – MrChrister 2008-12-09 22:13:11