js实例一个,包含日期格式化

$(document).ready(function() {
$('.moueseOver li').mousemove(function() {
$(this).siblings().removeClass('act');
$(this).addClass('act');
})
/*在头部banner里切换新闻模块*/
$('.banner li').click(function(){
var that = $(this);
var index = that.index();
that.siblings().removeClass('act');
that.addClass('act');
$('.news_list').hide();
$('.news_list').eq(index).show();
})
/*选中新闻*/
$('.news_list li .more').mouseover(function() {
$('.more').removeClass('act');
$(this).addClass('act');
})
/*点击新闻跳转到新闻正文*/
$('.news_list li').click(function(){
$(location).attr('href', 'news_text.html');
})
/*底部分页鼠标移入效果*/
$('.paging li').not('.num').mouseover(function() {
$(this).siblings().removeClass('act');
$(this).addClass('act')
})

$('.search_btn').click(function(){
var columnId = $('.banner .act').attr('attr');
var title = $('#search').val();
var currUrl = window.location.href;
var temp = currUrl.replace('http://', '');
var url = 'http://' + temp.substring(0, temp.indexOf("/")) + '/cms/api/findArticles/';
if (title == '') {
window.location.reload();
return;
}
$.ajax({
url : url,
data:{columnId:columnId,title:title},
type : 'POST',
success : function(data) { //若Ajax处理成功后返回的信息
if(data != null && data != ''){
$('.news_list').addClass('show').empty();
$('.search_fail').hide();
$('.paging').hide();
var str='';  
for(var i = 0; i < data.length; i++){  
var article = data[i];
var imgpath = path + '/img/no_img.jpg';
if (article.uploads != null) {
imgpath = article.uploads[0].path;
}
 
url = currUrl.substring(0, currUrl.lastIndexOf("/"));
//这里将数据库中查出来数据添加到ul
str+='<li><img src="' + imgpath + '" alt="" class="news_img">' +
'<div class = "content"><a href = "' + url + '/' + article.articleId + '.shtml">' +
'<p class="title">' + article.title + '</p></a>' +
'<p class="text">' + article.subTitle + '</p><p class="date">' + 
new Date(article.createTime).Format("yyyy/MM/dd") + '</p>'+
'<a href = "' + url + '/' + article.articleId + '.shtml"><p class="more">MORE</p></a></div></li>';
}
$('.news_list').html(str);  
} else {
$('.search_fail').show();
$('.news_list').removeClass('show');
$('.paging').hide();
}  
}
});
})

Date.prototype.Format = function (fmt) {    
var o = {    
"M+": this.getMonth() + 1, //月份     
"d+": this.getDate(), //日     
"H+": this.getHours(), //小时     
"m+": this.getMinutes(), //分     
"s+": this.getSeconds(), //秒     
"q+": Math.floor((this.getMonth() + 3) / 3), //季度     
"S": this.getMilliseconds() //毫秒     
};    
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));    
for (var k in o)    
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));    
return fmt;    
}    
});

猜你喜欢

转载自blog.csdn.net/m_jack/article/details/80512905