class Foo{
constructor(name) {
this.name = name
} greet() {
console.log('hello this is',this.name)
} someThingAsync() {
return Promise.resolve()
} asyncGreet() {
this.someThingAsync().then(this.greet.bind(this))
}
} new Foo('DOG').asyncGreet(); //生成六位数的验证码
//方法1
console.log((Math.floor(Math.random() * 999999)));
//方法2
console.log(Math.random().toString().slice(-6));
//方法3
console.log(Math.random().toFixed(6).slice(-6));
//方法4

document.querySelectorAll('#id').style.color = 'red';
document.querySelectorAll('#id').style.fontSize = '12px';
document.querySelectorAll('#id').style.background = 'red';

函数封装

function hdq(selector,color){
document.querySelectorAll(selector)[0].style.color = color
}

hdq('#d','red')

function item(selector,color) {
document.querySelectorAll(selector,color)
}

function getElement(selector) {
this.style = document.querySelectorAll(selector).style
}

getElement.prototype.color = function(color) {
this.style.color = color
return this
}

getElement.prototype.fontSize = function(fontSize) {
this.style.fontSize = fontSize
return this
}

getElement.prototype.background = function(bg) {
this.style.background = bg
return this
}

var el = new getElement("#div")

el.color('bule').background('#333').fontSize('16px')

												

js简单封装样式的更多相关文章

  1. js 简单的样式封装

    <script> function test(value){ var str=value; document.write("<div style=\"width: ...

  2. js设置css样式.

    在js设置css样式做法 var obj = document.getElementById('div'); obj.style.width = '100px'; obj.style.height = ...

  3. 原生js简单调用百度翻译API实现的翻译工具

    先来个在线demo: js翻译工具 或者百度搜索js简单调用百度翻译API工具(不过有个小小的界面显示bug,我想细心的人应该会发现) 或者直接前往该网址:js翻译工具 或者前往我的github:gi ...

  4. 常用js方法封装

    常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...

  5. php有效的过滤html标签,js代码,css样式标签

    过滤html标签�php中太简单了,我们可以直接使用strip_tags函数来实现了,下面给各位整理了一些关于 strip_tags函数的例子. php过滤html的函数:strip_tags(str ...

  6. js动态创建样式: style 和 link

    js动态创建样式: style 和 link ie6 不能 document.createElement('style') 然后append到head标签里.所以就找到这样个好文章 有很多提供动态创建 ...

  7. jquery简单封装

    对Raphael画图标的一个jquery简单封装 公司要做一个项目的demo,要求地图上可以插红旗,所以就用到了Raphael. 因为是个demo,所以地图就用了一张图片,效果如下: 所以为了更好的封 ...

  8. 原生js更改css样式的两种方式

    下面我给大家介绍的是原生js更改CSS样式的两种方式: 1通过在javascript代码中的node.style.cssText="css表达式1:css表达式2:css表达式3  &quo ...

  9. 简单封装mongodb

    首先安装mongodb  npm i mongodb --save 简单封装,在modules目录下新建db.js var MongoClient=require('mongodb').MongoCl ...

随机推荐

  1. 利用h5 meta 头标签设置og属性进行帖子分享图片时而有时而无

    <meta property="og:title" content="fgsfg"> <meta property="og:desc ...

  2. img添加预加载图片

    < img src="images/logo.png" onerror="javascript:this.src='images/logoError.png';&q ...

  3. 【Rice】Cultivar versus Variety

    From Cindy Haynes, Department of Horticulture   As a horticulturist, it is important that I use the ...

  4. 通过Charles获取看书神器API

    Charles Charles是一个可以做HTTP代理/ HTTP监视器/反向代理的软件,使开发人员能够查看其机器和Internet之间的所有HTTP和SSL / HTTPS流量.包括请求,响应和HT ...

  5. 解决Postman User-Agent 设置失效

    问题: 设置header中的UserAgent选项,抓包以后依然还是默认头信息 test Domain www.baidu.com Iphone6 UserAgent访问效果 User-Agent: ...

  6. textspan 转连接

    import 'package:flutter/material.dart'; import 'package:flutter/gestures.dart'; import 'package:url_ ...

  7. 如何加速GitHub访问速度

    http://tool.chinaz.com/网站中填入assets-cdn.github.com选取响应最小的ip,将ip.域名填入到C:\Windows\System32\drivers\etc下 ...

  8. Ubuntu 远程 Jupyter 配置

    Ubuntu 远程 Jupyter 配置 每次上课都要重新部署环境,最近看到阿里云的大学生优惠活动,就着手了一台云服务器,于是就把环境部署在上面了. 环境:阿里云 Ubuntu 16.04 64位 新 ...

  9. mysql查询表是否存在

    查询表是否存在 SHOW TABLES LIKE "表名" tp5查询表是否存在 Db::query('SHOW TABLES LIKE "表名"');

  10. C++_day06_运算符重载_智能指针

    1.只有函数运算符可以带缺省函数,其他运算符函数主要由操作符个数确定 2.解引用运算符和指针运算符 示例代码: #include <iostream> using namespace st ...