jQuery插件初级练习4答案

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
}
})

posted on 2018-05-24 21:30  革命军总部  阅读(105)  评论(0)    收藏  举报