The first three articles came up with one goal: no refresh paging. This article will implement the second goal of previewing news content. There are two ways to get a preview of the content, one for Ajax and one for pseudo Ajax (let's call it that).
We first use pseudo Ajax to achieve news content preview. The simple way to do this is to read the news list and see what's going to be previewed but not on the page, and display the preview when the mouse moves over the link. It's simple to realize,
We can assign the contents of the preview to the title attribute in the hyperlink tag, and then display it in the MouseHover. Here's how to implement a preview of the news.
Here we use a jquery plugin Nicetitle
Nicetitle is a plugin that displays hints when you move the mouse over a hyperlink. We can use this plugin to implement news, text preview.
This is not a real preview that reads the text list while reading the content profile for each article (that is, what you want to preview), and then use the plugin to implement a fake preview.
The effect diagram is as follows, you can modify it accordingly
The code is as follows:
<link rel="Stylesheet" type="text/css" href="Styles/jQuery.niceTitle.css" />
<script type="text/javascript" src="Scripts/jQuery.niceTitle.js"></script>
<script type="text/javascript">
$(function () {
$("a[class=info]").niceTitle();
});
</script>
<a href='链接地址' title='预览的内容' class="info">链接名 </a>
The following should be modified in the previous article:
1. Modify query conditions and increase the interception of strings in NewsHandler.ashx.cs
String cmdtext = "Select News_id,news_title,news_readtimes,news_time from" + table + ' ORDER BY ' + order + "desc";
To
String cmdtext = "SELECT * from" + table + ' ORDER BY ' + by + "desc";
and add the following code to control what is returned is the content of the preview rather than the content of the news:
//将dt中news_content的字数都控制在300个字多余的使用...
if (dt != null || dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["news_content"].ToString().Length > 300)
{
dt.Rows[i]["news_content"] = dt.Rows[i]["news_content"].ToString ().Substring(0, 299) + "...";
}
}
}