怎么把下面的jquery封装到一个JS文件中,用的时候可以调用 5
<script>vart=n=0,count=$("#playShowa").size();$(function(){$("#playShowa:not(:first-c...
<script>
var t = n = 0, count = $("#playShow a").size();
$(function(){
$("#playShow a:not(:first-child)").hide();
$("#playText").html($("#playShow a:first-child").find("img").attr('alt'));
$("#playNum a:first").addClass('on');
$("#playText").click(function(){window.open($("#playShow a:first-child").attr('href'), "_blank")});
$("#playNum a").click(function() {
var i = $(this).text() - 1;
n = i;
if (i >= count) return;
$("#playText").html($("#playShow a").eq(i).find("img").attr('alt'));
$("#playText").unbind().click(function(){window.open($("#playShow a").eq(i).attr('href'), "_blank")})
$("#playShow a").filter(":visible").hide().parent().children().eq(i).fadeIn(1200);
$(this).addClass('on').siblings().removeClass('on');
});
t = setInterval("showAuto()", 5000);
$("#play").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 5000);});
});
function showAuto()
{
n = n >= (count - 1) ? 0 : ++n;
$("#playNum a").eq(n).trigger('click');
};
</script> 展开
var t = n = 0, count = $("#playShow a").size();
$(function(){
$("#playShow a:not(:first-child)").hide();
$("#playText").html($("#playShow a:first-child").find("img").attr('alt'));
$("#playNum a:first").addClass('on');
$("#playText").click(function(){window.open($("#playShow a:first-child").attr('href'), "_blank")});
$("#playNum a").click(function() {
var i = $(this).text() - 1;
n = i;
if (i >= count) return;
$("#playText").html($("#playShow a").eq(i).find("img").attr('alt'));
$("#playText").unbind().click(function(){window.open($("#playShow a").eq(i).attr('href'), "_blank")})
$("#playShow a").filter(":visible").hide().parent().children().eq(i).fadeIn(1200);
$(this).addClass('on').siblings().removeClass('on');
});
t = setInterval("showAuto()", 5000);
$("#play").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 5000);});
});
function showAuto()
{
n = n >= (count - 1) ? 0 : ++n;
$("#playNum a").eq(n).trigger('click');
};
</script> 展开
展开全部
基于jquery封装的一个js分页代码:
(function ($) {
var PageFunc = function PageFunc() { }
$.PageFunc = function (Total, PageSize, curPageNum, FunUrl) {
if (PageSize == "" || PageSize == null || PageSize == undefined) {
PageSize = 10;
}
if (curPageNum == "" || curPageNum == null || curPageNum == undefined) {
curPageNum = 1;
}
//计算总页数
Total = parseInt(Total); //总记录数
PageSize = parseInt(PageSize); //每页显示数
curPageNum = parseInt(curPageNum); //当前页
//总页数
var AllPage = Math.floor(Total / PageSize);
if (Total % PageSize != 0) {
AllPage++;
}
var navHtml = "";
if (curPageNum <= 0)
curPageNum = 1;
if (AllPage > 1) {
if (curPageNum != 1) {
//处理首页连接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('1')\" >|<</a></span> ";
}
if (curPageNum > 1) {
//处理上一页的连接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (curPageNum - 1) + "')\" ><<</a></span> ";
}
else {
navHtml += "<span class=\"disabled\"><<</span> ";
}
var currint = 5;
for (var i = 0; i <= 10; i++) {
//一共最多显示10个页码,前面5个,后面5个
if ((curPageNum + i - currint) >= 1 && (curPageNum + i - currint) <= AllPage)
if (currint == i) {
//当前页处理
navHtml += "<span lass=\"current\">[" + curPageNum + "]</span> ";
}
else {
//一般页处理
var n = curPageNum + i - currint;
navHtml += "<a href=\"javascript:" + FunUrl + "('" + (parseInt(n)) + "')\">" + n + "</a> ";
}
}
if (curPageNum < AllPage) {
//处理下一页的链接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (parseInt(curPageNum) + 1) + "')\">>></a></span> ";
}
else {
navHtml += "<span class=\"disabled\">>></span> ";
}
if (curPageNum != AllPage) {
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + AllPage + "')\" >>|</a></span> ";
}
}
navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> ";
return navHtml;
};
})(jQuery);
下边是调用方法:
function QueryList(curpage) {
if (curpage == "" || curpage == null || curpage == undefined) {
curpage = 1;
}
var pagesize = 10;
var Countys = $("#Countys").val(); //县
var enddate = $("#enddate").val(); //结束时间
var begindate = $("#begindate").val(); //开始时间
$.ajax({
url: "",
type: "POST",
data: { "Countys": Countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
dataType: "json",
error: function (xhr, status, errMsg) { window.location.href = "/CommonError/index/" + errMsg.code + "?txt=" + errMsg.msg; },
success: function (mydata) {
var str = "";
$.each(mydata.Tdata, function (i, item) {
str += "<tr>"
str += "<td>" + $.FormatDateTime(item.ControlBeginTime, false) + "</td>";
str += "<td>" + $.FormatDateTime(item.ControlEndTime, false) + "</td>";
str += "<td>" + item.Name + "</td>";
str += "<td>" + item.PlateNumber + "</td>";
str += "<td>" + item.ControlDept + "</td>";
if (item.IsAll == "0") {
str += "<td>全县布控</td>";
}
else {
str += "<td>按卡口点布控</td>";
}
str += "<td>" + item.IsAll == "0" ? "全县布控" : "按卡口点布控" + "</td>";
str += "<td>修改</td>";
str += "<td>删除</td>";
str += "<td>详细</td>";
str + "</tr>";
});
$("#srh_rslt tbody").html(str);
$(".pagination").html($.PageFunc(mydata.total, pagesize, curpage, "QueryList"));
}
});
}
(function ($) {
var PageFunc = function PageFunc() { }
$.PageFunc = function (Total, PageSize, curPageNum, FunUrl) {
if (PageSize == "" || PageSize == null || PageSize == undefined) {
PageSize = 10;
}
if (curPageNum == "" || curPageNum == null || curPageNum == undefined) {
curPageNum = 1;
}
//计算总页数
Total = parseInt(Total); //总记录数
PageSize = parseInt(PageSize); //每页显示数
curPageNum = parseInt(curPageNum); //当前页
//总页数
var AllPage = Math.floor(Total / PageSize);
if (Total % PageSize != 0) {
AllPage++;
}
var navHtml = "";
if (curPageNum <= 0)
curPageNum = 1;
if (AllPage > 1) {
if (curPageNum != 1) {
//处理首页连接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('1')\" >|<</a></span> ";
}
if (curPageNum > 1) {
//处理上一页的连接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (curPageNum - 1) + "')\" ><<</a></span> ";
}
else {
navHtml += "<span class=\"disabled\"><<</span> ";
}
var currint = 5;
for (var i = 0; i <= 10; i++) {
//一共最多显示10个页码,前面5个,后面5个
if ((curPageNum + i - currint) >= 1 && (curPageNum + i - currint) <= AllPage)
if (currint == i) {
//当前页处理
navHtml += "<span lass=\"current\">[" + curPageNum + "]</span> ";
}
else {
//一般页处理
var n = curPageNum + i - currint;
navHtml += "<a href=\"javascript:" + FunUrl + "('" + (parseInt(n)) + "')\">" + n + "</a> ";
}
}
if (curPageNum < AllPage) {
//处理下一页的链接
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (parseInt(curPageNum) + 1) + "')\">>></a></span> ";
}
else {
navHtml += "<span class=\"disabled\">>></span> ";
}
if (curPageNum != AllPage) {
navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + AllPage + "')\" >>|</a></span> ";
}
}
navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> ";
return navHtml;
};
})(jQuery);
下边是调用方法:
function QueryList(curpage) {
if (curpage == "" || curpage == null || curpage == undefined) {
curpage = 1;
}
var pagesize = 10;
var Countys = $("#Countys").val(); //县
var enddate = $("#enddate").val(); //结束时间
var begindate = $("#begindate").val(); //开始时间
$.ajax({
url: "",
type: "POST",
data: { "Countys": Countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
dataType: "json",
error: function (xhr, status, errMsg) { window.location.href = "/CommonError/index/" + errMsg.code + "?txt=" + errMsg.msg; },
success: function (mydata) {
var str = "";
$.each(mydata.Tdata, function (i, item) {
str += "<tr>"
str += "<td>" + $.FormatDateTime(item.ControlBeginTime, false) + "</td>";
str += "<td>" + $.FormatDateTime(item.ControlEndTime, false) + "</td>";
str += "<td>" + item.Name + "</td>";
str += "<td>" + item.PlateNumber + "</td>";
str += "<td>" + item.ControlDept + "</td>";
if (item.IsAll == "0") {
str += "<td>全县布控</td>";
}
else {
str += "<td>按卡口点布控</td>";
}
str += "<td>" + item.IsAll == "0" ? "全县布控" : "按卡口点布控" + "</td>";
str += "<td>修改</td>";
str += "<td>删除</td>";
str += "<td>详细</td>";
str + "</tr>";
});
$("#srh_rslt tbody").html(str);
$(".pagination").html($.PageFunc(mydata.total, pagesize, curpage, "QueryList"));
}
});
}
展开全部
把上面的代码去掉<script></script>标签, 把其它的复制到一个JS文件中, 在需要用到这段JS的页面中引入你保存的那个JS文件就可以了, 例, 你保存为a.js 在页面中引入: <script src="路径/a.js"></script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(
$.fn.myfn=function(){
/*
这里加上你的代码
以后可以用$().myfn()调用
*/
}
)(jQuery)
$.fn.myfn=function(){
/*
这里加上你的代码
以后可以用$().myfn()调用
*/
}
)(jQuery)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询