最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Ajax讀取txt并對(duì)txt內(nèi)容進(jìn)行分頁(yè)顯示功能

 更新時(shí)間:2016年11月15日 11:15:47   作者:Asia小程  
這篇文章給大家介紹了Ajax讀取txt并對(duì)txt內(nèi)容進(jìn)行分頁(yè)顯示功能,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧

下文給大家分享了ajax讀取txt并對(duì)txt內(nèi)容進(jìn)行分頁(yè)顯示的核心代碼,廢話(huà)不多說(shuō)了,直接貼代碼了。

function TransferString(content)
{
var string = content;
try{
string=string.replace(/\r\n/g,"<BR>")
string=string.replace(/\n/g,"<BR>");
string=string.replace(/[ ]/g,"&nbsp;")
string=string.replace(/\ +/g,"&nbsp;")
}catch(e) {
alert(e.message);
}
return string;
}
var pageIndex = 1;
var id = $("#aId").val();
var url = $('#urlArticleContent').val();
var txt = '';
var pageSize = @(ConfigurationManager.AppSettings["ArticlepageSize"]);
var page=5;
var pageCount = 0;
$(function() {
if(url!="")
{
txt = ($.ajax({ url: url, async: false })).responseText;
if (txt.indexOf('http://www.w3.org/1999/xhtml')==-1) {
pageCount = Math.ceil(txt.length / pageSize);
$("#PageCount").html(pageCount);
$('#word').html(TransferString(txt.substring(0, pageSize)));
$('#demo').pagination({
dataSource: function(done){
var result = [];
for (var i = 1; i < pageCount; i++) {
result.push(i);
}
done(result);
},
pageCount:pageCount,
pageSize: 5,
showGoInput: true,
showGoButton: true,
callback: function(data, pagination) {
// template method of yourself
var html = template(data);
dataContainer.html(html);
}
})
} else {
txt = '';
}
}
})
function GoHead() {
GoPage(1);
}
function NextClick() {
if (pageIndex < pageCount) {
pageIndex = pageIndex + 1;
} else {
pageIndex = pageCount;
}
GoPage(pageIndex);
$("#pageCurrent").html(pageIndex);
}
function backClick() {
if (pageIndex > 1) {
pageIndex = pageIndex - 1;
GoPage(pageIndex);
$("#pageCurrent").html(pageIndex);
}
}
function GoPageNew() {
var page=$("#pageGo").val();
GoPage(page);
opts.current=page;
}
function GoPage(pageIndex) {
if(pageIndex==0) {
pageIndexStr = $('#goPage').val();
if (pageIndexStr==undefined) {
return false;
}
pageIndexStr = pageIndexStr.trim();
var pageIndex = parseInt(pageIndexStr);
}
$('#page'+pageIndex).siblings().removeClass('active');
$('#page'+pageIndex).addClass('active');
if (pageIndex==1) {
if(!$('#backClick').hasClass('disabled')) {
$('#backClick').addClass('disabled');
}
} else {
$('#backClick').removeClass('disabled');
}
if (pageIndex == pageCount) {
if(!$('#nextClick').hasClass('disabled')) {
$('#nextClick').addClass('disabled');
}
} else {
$('#nextClick').removeClass('disabled');
}
var pageTxt = txt.substring((pageIndex - 1) * pageSize, pageIndex * pageSize);
$('#word').html(TransferString(pageTxt));
$('html, body').animate({
'scrollTop': 0
}, 0);
$("#pageCurrent").html(pageIndex);
}
function PageGo(){ if($('.jump-ipt').val()!=''){
GoPage($('.jump-ipt').val())
}
}
@{
if (null != ViewBag.Ariticle)
{
DataRow dr = ViewBag.Ariticle;
if (null != dr)
{
ViewBag.Title = dr["Title"];
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="breadcrumb_block">
<span class="tit"><a href="/web/sciencefiction/index">科普IP</a> &gt;</span>
<ol class="breadcrumb">
<li class="active">@dr["Title"]</li>
<li class="active">在線試讀</li>
</ol>
<div class="clear"></div>
</div>
</div>
<div class="col-sm-8">
<input type="hidden" name="aId" id="aId" value="@Request["id"]" />
<div class="read_book">
<h3 class="read_tit">@dr["Title"]</h3>
<div class="author">
<span class="ml30"><em id="pageCurrent">1</em>/<em id="PageCount">0</em></span>
</div>
<input type="hidden" value="@dr["FilePath"]" id="urlArticleContent">
<div class="word" id="word">
<nav class="page-my">
<ul class="pagination pull-right fs14" id="demo"></ul>
<div class="clear"></div>
</nav>
<!--底部翻頁(yè)-->
</div>
<div class="col-sm-3">
<input type="hidden" name="pageCount" id="pageCount" value="@ViewBag.pageCount" />
<!--閱讀控制-->
<div class="read_control">
<a href="javascript:;" onclick="backClick()"><span class="icon icon01"></span><em>上一頁(yè)</em></a>
<a href="javascript:;" onclick="NextClick()"><span class="icon icon02"></span><em>下一頁(yè)</em></a>
<a href="javascript:;" onclick="GoHead()"><span class="icon icon03"></span><em>回首頁(yè)</em></a>
</div>
</div>
</div>
</div>
}
}
}

txt文件上傳時(shí)需要做一些處理,否則只能顯示UTF8格式的txt

/// <summary>
/// 文件上傳
/// </summary>
/// <returns></returns>
public JsonResult UploadFiles()
{

HttpPostedFileBase postFile = HttpContext.Request.Files["filesave"];
if (postFile != null)
{
string fileName = Path.GetFileName(postFile.FileName);
string fileExt = Path.GetExtension(fileName.ToLower());
string fileSize = postFile.ContentLength.ToString();
long fileNameTem = Common.GenerateLongId();
string sPath = string.Format("/Data/Material/{0}_{1}.txt", fileNameTem.ToString(), fileName.Replace(".txt", ""));//Guid.NewGuid().ToString().Replace("-", "")
string viewUrl = string.Empty;
string g = Guid.NewGuid().ToString();
if (!Directory.Exists(Server.MapPath("~") + "/Data/Material"))
Directory.CreateDirectory(Server.MapPath("~") + "/Data/Material");
string p = Server.MapPath(sPath);
postFile.SaveAs(p);

if (System.IO.File.Exists(p))
{
StreamReader sr = new StreamReader(p, System.Text.Encoding.Default);
String input = sr.ReadToEnd();
sr.Close();

StreamWriter sw = new StreamWriter(p, false, System.Text.Encoding.UTF8);
sw.WriteLine(input);
sw.Close();
}
return Json(new { FilePath = sPath, FileName = fileName, viewurl = viewUrl, fileSize = fileSize });
}
else
{
return Json(new { FilePath = "" });
}
}

另外頁(yè)面首頁(yè)引入js

<script src="~/Scripts/web/jquery.pagination.js"></script>
<link href="~/Content/jquery.pagination.css" rel="stylesheet" />
/**
* pagination分頁(yè)插件
* @version 1.1.2
* @author mss
* @url http://maxiaoxiang.com/plugin/pagination.html
* @E-mail 251445460@qq.com
*
* @調(diào)用方法
* $(selector).pagination();
* 
* @更新日志
* 2016-07-25:修復(fù)click重復(fù)事件
*/
; (function ($, window, document, undefined) {
//配置參數(shù)
var defaults = {
totalData: 0, //數(shù)據(jù)總條數(shù)
showData: 0, //每頁(yè)顯示的條數(shù)
pageCount: 9, //總頁(yè)數(shù),默認(rèn)為9
current: 1, //當(dāng)前第幾頁(yè)
prevCls: 'prev', //上一頁(yè)class
nextCls: 'next', //下一頁(yè)class
prevContent: '上一頁(yè)', //上一頁(yè)內(nèi)容
nextContent: '下一頁(yè)', //下一頁(yè)內(nèi)容
activeCls: 'active', //當(dāng)前頁(yè)選中狀態(tài)
coping: false, //首頁(yè)和尾頁(yè)
homePage: '', //首頁(yè)節(jié)點(diǎn)內(nèi)容
endPage: '', //尾頁(yè)節(jié)點(diǎn)內(nèi)容
count: 5, //當(dāng)前頁(yè)前后分頁(yè)個(gè)數(shù)
jump: true, //跳轉(zhuǎn)到指定頁(yè)數(shù)
jumpIptCls: 'jump-ipt', //文本框內(nèi)容
jumpBtnCls: 'jump-btn', //跳轉(zhuǎn)按鈕
jumpBtn: '跳轉(zhuǎn)', //跳轉(zhuǎn)按鈕文本
callback: function () { 
} //回調(diào)
};
var Pagination = function (element, options) {
//全局變量
var opts = options,//配置
current,//當(dāng)前頁(yè)
$document = $(document),
$obj = $(element);//容器
/**
* 設(shè)置總頁(yè)數(shù)
* @param int page 頁(yè)碼
* @return opts.pageCount 總頁(yè)數(shù)配置
*/
this.setTotalPage = function (page) {
return opts.pageCount = page;
};
/**
* 獲取總頁(yè)數(shù)
* @return int p 總頁(yè)數(shù)
*/
this.getTotalPage = function () {
var p = opts.totalData || opts.showData ? Math.ceil(parseInt(opts.totalData) / opts.showData) : opts.pageCount;
return p;
};
//獲取當(dāng)前頁(yè)
this.getCurrent = function () {
return current;
};
/**
* 填充數(shù)據(jù)
* @param int index 頁(yè)碼
*/
this.filling = function (index) {
var html = '';
current = index || opts.current;//當(dāng)前頁(yè)碼
var pageCount = this.getTotalPage();
if (current > 1) {//上一頁(yè)
html += '<li onclick=GoPage(' + (current - 1) + ')><a href="javascript:;" class="' + opts.prevCls + '">' + opts.prevContent + '</a></li>';
} else {
$obj.find('.' + opts.prevCls) && $obj.find('.' + opts.prevCls).remove();
}
if (current >= opts.count * 2 && current != 1 && pageCount != opts.count) {
var home = opts.coping && opts.homePage ? opts.homePage : '1';
html += opts.coping ? '<li onclick=GoPage(' + home + ')><a href="javascript:;" data-page="1">' + home + '</a></li><span>...</span>' : '';
}
var start = current - opts.count,
end = current + opts.count;
((start > 1 && current < opts.count) || current == 1) && end++;
(current > pageCount - opts.count && current >= pageCount) && start++;
for (; start <= end; start++) {
if (start <= pageCount && start >= 1) {
if (start != current) {
html += '<li onclick=GoPage(' + start + ')><a href="javascript:;" data-page="' + start + '">' + start + '</a></li>';
} else {
html += '<li class="' + opts.activeCls + '" onclick=GoPage(' + start + ')><a href="javascript:;"><span>' + start + '</span></a></li>';
}
}
}
if (current + opts.count < pageCount && current >= 1 && pageCount > opts.count) {
var end = opts.coping && opts.endPage ? opts.endPage : pageCount;
html += opts.coping ? '<span>...</span><li onclick=GoPage(' + pageCount + ')><a href="javascript:;" data-page="' + pageCount + '">' + end + '</a></li>' : '';
}
if (current < pageCount) {//下一頁(yè)
html += '<li onclick=GoPage(' + (current + 1) + ')><a href="javascript:;" class="' + opts.nextCls + '">' + opts.nextContent + '</a></li>'
} else {
$obj.find('.' + opts.nextCls) && $obj.find('.' + opts.nextCls).remove();
}
html += opts.jump ? '<input type="text" class="' + opts.jumpIptCls + '"><a href="javascript:;" onclick=PageGo() class="' + opts.jumpBtnCls + '">' + opts.jumpBtn + '</a>' : '';
$obj.empty().html(html);
};
//綁定事件
this.eventBind = function () {
var self = this;
var pageCount = this.getTotalPage();//總頁(yè)數(shù)
$obj.off().on('click', 'a', function () {
if ($(this).hasClass(opts.nextCls)) {
var index = parseInt($obj.find('.' + opts.activeCls).text()) + 1;
} else if ($(this).hasClass(opts.prevCls)) {
var index = parseInt($obj.find('.' + opts.activeCls).text()) - 1;
} else if ($(this).hasClass(opts.jumpBtnCls)) {
if ($obj.find('.' + opts.jumpIptCls).val() !== '') {
var index = parseInt($obj.find('.' + opts.jumpIptCls).val());
} else {
return;
}
} else {
var index = parseInt($(this).data('page'));
}
self.filling(index);
typeof opts.callback === 'function' && opts.callback(self);
});
//輸入跳轉(zhuǎn)的頁(yè)碼
$obj.on('input propertychange', '.' + opts.jumpIptCls, function () {
var $this = $(this);
var val = $this.val();
var reg = /[^\d]/g;
if (reg.test(val)) {
$this.val(val.replace(reg, ''));
}
(parseInt(val) > pageCount) && $this.val(pageCount);
if (parseInt(val) === 0) {//最小值為1
$this.val(1);
}
});
//回車(chē)跳轉(zhuǎn)指定頁(yè)碼
$document.keydown(function (e) {
var self = this;
if (e.keyCode == 13 && $obj.find('.' + opts.jumpIptCls).val()) {
var index = parseInt($obj.find('.' + opts.jumpIptCls).val());
GoPage(index);
//self.filling(index);
//typeof opts.callback === 'function' && opts.callback(self);
}
});
};
//初始化
this.init = function () {
this.filling(opts.current);
this.eventBind();
};
this.init();
};
$.fn.pagination = function (parameter, callback) {
if (typeof parameter == 'function') {//重載
callback = parameter;
parameter = {};
} else {
parameter = parameter || {};
callback = callback || function () { };
}
var options = $.extend({}, defaults, parameter);
return this.each(function () {
var pagination = new Pagination(this, options);
callback(pagination);
});
};
})(jQuery, window, document);

以上所述是小編給大家介紹的Ajax讀取txt并對(duì)txt內(nèi)容進(jìn)行分頁(yè)顯示,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 使用jquery 的ajax調(diào)用總是錯(cuò)誤親測(cè)的解決方法

    使用jquery 的ajax調(diào)用總是錯(cuò)誤親測(cè)的解決方法

    使用jquery 的ajax功能調(diào)用一個(gè)頁(yè)面,卻發(fā)現(xiàn)總是出現(xiàn)錯(cuò)誤,經(jīng)過(guò)這么多測(cè)試終于正常了,尤其是 dataType: 'json',看來(lái)jquery有很?chē)?yán)格的驗(yàn)證機(jī)制
    2013-07-07
  • Ajax跨域登錄請(qǐng)求未攜帶cookie錯(cuò)誤解決

    Ajax跨域登錄請(qǐng)求未攜帶cookie錯(cuò)誤解決

    這篇文章主要為大家介紹了Ajax跨域登錄請(qǐng)求未攜帶cookie錯(cuò)誤解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • AJAX聊天室V1.0發(fā)布

    AJAX聊天室V1.0發(fā)布

    AJAX聊天室V1.0發(fā)布...
    2006-09-09
  • ajax完美解決的下拉框的onchange問(wèn)題

    ajax完美解決的下拉框的onchange問(wèn)題

    最近老總提了一個(gè)小功能,在搜索網(wǎng)吧列表的時(shí)候加上網(wǎng)吧所屬代理商這個(gè)條件,原有的搜索條件是一個(gè)地區(qū)二級(jí)聯(lián)動(dòng),現(xiàn)在需要根據(jù)不同的地區(qū)顯示不同的代理商集合。
    2010-08-08
  • ajax實(shí)現(xiàn)簡(jiǎn)單登錄頁(yè)面

    ajax實(shí)現(xiàn)簡(jiǎn)單登錄頁(yè)面

    這篇文章主要為大家詳細(xì)介紹了ajax實(shí)現(xiàn)簡(jiǎn)單登錄頁(yè)面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • Ajax基礎(chǔ)與登入教程

    Ajax基礎(chǔ)與登入教程

    Ajax 是 Asynchronous JavaScript and XML的縮寫(xiě)。其優(yōu)點(diǎn)可以減輕服務(wù)器的負(fù)擔(dān),按需取數(shù)據(jù),最大程度的減少冗余請(qǐng)求。接下來(lái)通過(guò)本文給大家介紹Ajax基礎(chǔ)與登入教程,需要的的朋友參考下
    2017-03-03
  • Flash & Ajax 操作 XML 實(shí)例:無(wú)刷新分頁(yè)

    Flash & Ajax 操作 XML 實(shí)例:無(wú)刷新分頁(yè)

    Flash & Ajax 操作 XML 實(shí)例:無(wú)刷新分頁(yè)...
    2006-08-08
  • AJAX 支持搜索引擎問(wèn)題分析

    AJAX 支持搜索引擎問(wèn)題分析

    AJAX是利用瀏覽器的兩個(gè)內(nèi)置對(duì)象實(shí)現(xiàn)了,異步傳輸,說(shuō)白了,頁(yè)面不刷新對(duì)后臺(tái)請(qǐng)求功能,現(xiàn)在市面上有很多AJAX框架,我就不一一列舉了。
    2009-02-02
  • php ajax無(wú)刷新上傳圖片實(shí)例代碼

    php ajax無(wú)刷新上傳圖片實(shí)例代碼

    將index.html和upload.php文件保存到支持php的空間的同級(jí)目錄,測(cè)試運(yùn)行即可
    2008-09-09
  • AJAX(XMLHttpRequest.status)狀態(tài)碼

    AJAX(XMLHttpRequest.status)狀態(tài)碼

    本文羅列了一些Jquery中AJAX參數(shù)詳細(xì)列表及XMLHttpRequest.status狀態(tài)嗎,感興趣的你可以參考下,希望對(duì)你學(xué)習(xí)ajax有所幫助
    2013-02-02

最新評(píng)論

济阳县| 黑水县| 鄂温| 邯郸县| 青岛市| 嘉鱼县| 广东省| 屯门区| 娱乐| 鄂伦春自治旗| 黄浦区| 东山县| 青阳县| 四会市| 高要市| 平潭县| 平度市| 达拉特旗| 汪清县| 肥乡县| 尼玛县| 瓮安县| 黑水县| 庆元县| 永吉县| 晋宁县| 韶山市| 视频| 旺苍县| 桦南县| 教育| 常宁市| 凌源市| 黎平县| 龙泉市| 宾川县| 建阳市| 西昌市| 阳原县| 长泰县| 铜梁县|