jquery 结合C#后台的数组对文章的关键字自动添加链接的代码
更新时间:2011年07月15日 00:57:35 作者:
jquery 结合C#后台的数组对文章的关键字自动添加链接的代码,需要的朋友可以参考下。
当我们需要在后台读取多个关键字时,我们可以先把后台的数据库读取到一个数组中(在数据库添加多个关键词时用“,”隔开):
public string[] str; //添加一个公共数组一遍jquery调用
protected void Page_Load(object sender, EventArgs e)
{
string str1 = 读取数据库的关键词;
str=str1.Split(',');
}
页面的JQuery:
<html s>
<head >
<script type="text/javascript">
$(document).ready(function(){
<%for(int i=0;i<str.Length;i++){ %>
$("#content").html($("#content").html().replace(/<%=str[i] %>/g, " <a href='http://www.baidu.com' ><%=str[i] %> </a>"));
<%} %>
});
</script>
</head>
<body>
<div id="content">
<%=文章%>
</div>
</body>
</html>
复制代码 代码如下:
public string[] str; //添加一个公共数组一遍jquery调用
protected void Page_Load(object sender, EventArgs e)
{
string str1 = 读取数据库的关键词;
str=str1.Split(',');
}
页面的JQuery:
<html s>
<head >
<script type="text/javascript">
$(document).ready(function(){
<%for(int i=0;i<str.Length;i++){ %>
$("#content").html($("#content").html().replace(/<%=str[i] %>/g, " <a href='http://www.baidu.com' ><%=str[i] %> </a>"));
<%} %>
});
</script>
</head>
<body>
<div id="content">
<%=文章%>
</div>
</body>
</html>
相关文章
如何让浏览器支持jquery ajax load 前进、后退功能
在做 ajax load 的时候,很多人都不会考虑到需要浏览器支持前进后退功能,本例让浏览器支持jquery ajax load 前进、后退 功能,需要的朋友可以参考下2014-06-06
如何使用jquery修改css中带有!important的样式属性
如何使用jquery修改css中带有!important的样式属性?下面小编就为大家带来一篇使用jquery修改css中带有!important的样式属性方法。希望对大家有所帮助。一起跟随小编过来看看吧2016-04-04
jQuery 1.0.4 - New Wave Javascript(js源文件)
jQuery 1.0.4 - New Wave Javascript(js源文件)...2007-01-01


最新评论