class Util { inject() { Element.prototype.remove = function (removeClassName) { this.classList.remove(removeClassName); } Element.prototype.add = function (addClassName) { this.classList.add(addClassName); } HTMLElement.prototype.text = function (text) { this.innerText = text; } HTMLElement.prototype.html = function (text) { this.innerHTML += text; } } header(title = "", icon, input = false) { $("body").html(`
${!input ? `
${title}
` : ``} ${icon}
`) click($(".icon-back1"), function () { history.back() }) } item(father, data) { data.forEach(v => { father.html(`
${v.total || v.shuliang}
${v.title}
模特:${v.user || v.renwulist[0].name}
机构:${v.source || v.jigoulist[0].name}
${(v.biaoqianlist || v.tags).map(j => { return `${j.name || j.title}` }).toString().replaceAll(",", "") }
`) }) } model(father, data) { data.forEach(v => { father.html(`
63套
${v.title}
`) }) } modelList(father, data) { //最外层数组,是个对象 father.html(`

${data.model_info.name}

${data.model_info.explain}

`) } testModelList(father, data) { //第二层,才是数组,只有数组才能循环 data.forEach((value, index) => { father.html(` `) }) } footer() { var ul = ` `; $("body").html(ul) } query(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } /** * className 可能的类型: * 对象类型,本质上是 Element 类型 * 数组类型,本质上是 NodeList 类型 */ click(className, callback) { // 不管是 Element 还是 NodeList 都统一转化为 Array类型 // 但如果 className 是 Element 类型,那么转换后数组为空:[] // 如果 className 是 NodeList 类型,那么转换后数组不为空: [ Element, Element ] // 因为已经都是数组,所以无需:Array.isArray() 来判断是否是数组了 // 只需要判断数值是否有数据即可 var domArr = Array.from(className); if (domArr.length != 0) { className.forEach((v, i) => { v.onclick = function (e) { v.index = i; v.e = e; callback.call(this) } }) } else { className.onclick = function (e) { className.e = e; callback.call(this) } } } $(className) { return document.querySelector(className) } _(className) { return document.querySelectorAll(className) } } var { $, _, click, inject, query, footer, item, header, model, modelList, testModelList } = new Util() inject()