jQuery插件初级练习4答案

时间:2023-12-02 19:41:08

html:

$("p").log().css("color","red")

jQuery:

$.fn.extend({
log: function() {
var date = new Date()
var year = date.getFullYear()
var month = date.getMonth() + 1 //月
var data = date.getDate() //日
var hours = date.getHours()
var min = date.getMinutes()
var seconds = date.getSeconds()
var day = date.getDay()
var time = year + "-" +month+ "-" + data + " " + hours + ":" + min + ":" +seconds+ " "
this.text(time)
   return this
}
})