js简单封装样式
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简单封装样式的更多相关文章
- js 简单的样式封装
<script> function test(value){ var str=value; document.write("<div style=\"width: ...
- js设置css样式.
在js设置css样式做法 var obj = document.getElementById('div'); obj.style.width = '100px'; obj.style.height = ...
- 原生js简单调用百度翻译API实现的翻译工具
先来个在线demo: js翻译工具 或者百度搜索js简单调用百度翻译API工具(不过有个小小的界面显示bug,我想细心的人应该会发现) 或者直接前往该网址:js翻译工具 或者前往我的github:gi ...
- 常用js方法封装
常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...
- php有效的过滤html标签,js代码,css样式标签
过滤html标签�php中太简单了,我们可以直接使用strip_tags函数来实现了,下面给各位整理了一些关于 strip_tags函数的例子. php过滤html的函数:strip_tags(str ...
- js动态创建样式: style 和 link
js动态创建样式: style 和 link ie6 不能 document.createElement('style') 然后append到head标签里.所以就找到这样个好文章 有很多提供动态创建 ...
- jquery简单封装
对Raphael画图标的一个jquery简单封装 公司要做一个项目的demo,要求地图上可以插红旗,所以就用到了Raphael. 因为是个demo,所以地图就用了一张图片,效果如下: 所以为了更好的封 ...
- 原生js更改css样式的两种方式
下面我给大家介绍的是原生js更改CSS样式的两种方式: 1通过在javascript代码中的node.style.cssText="css表达式1:css表达式2:css表达式3 &quo ...
- 简单封装mongodb
首先安装mongodb npm i mongodb --save 简单封装,在modules目录下新建db.js var MongoClient=require('mongodb').MongoCl ...
随机推荐
- 【题解】Luogu P4867 Gty的二逼妹子序列
原题传送门 同Luogu P4396 [AHOI2013]作业 询问多了10倍,但还能跑过(smog #include <bits/stdc++.h> #define N 100005 # ...
- C 语言多线程与锁机制
C 语言多线程与锁机制 多线程 #include <pthread.h> void *TrainModelThread(void *id) { ... pthread_exit(NULL) ...
- BZOJ5279: [Usaco2018 Open]Disruption
题目大意:给你一棵n个节点的树,这n条边称为原边,另给出m条带权值的额外边,求删去每条原边后通过给出的m额外条边变回一棵树的最小价值.题解:看完题面以为是Tarjan连通性之类的题目,冷静分析后想到是 ...
- 二分优化lis和STL函数
LIS:最长上升子序列: 这个题我们很显然会想到使用dp, 状态设计:dp[i]代表以a[i]结尾的LIS的长度 状态转移:dp[i]=max(dp[i], dp[j]+1) (0<=j< ...
- CEF 支持的命令行参数
参考:https://peter.sh/experiments/chromium-command-line-switches/ List of Chromium Command Line Switch ...
- cf C题
题意:矩阵只包含0,1两种数字,给你一个矩阵A,另一个矩阵B,每一次可以从A中选出一个子矩阵,点击一次使得这个子矩阵的四个角的数字变成与原来相反的数,0变1,1变0.问你可不可以经过有限次的变换把矩阵 ...
- 王之泰201771010131《面向对象程序设计(java)》第十四周学习总结
第一部分:理论知识学习部分 第12章 Swing用户界面组件 12.1.Swing和MVC设计模式 a 设计模式初识b 模型—视图—控制器模式c Swing组件的模型—视图—控制器分析 12.2布局管 ...
- 工作中常用的 Shell 命令及技巧
调试 bash 脚本的技巧 加 -x 参数运行 bash 脚本时,会显示执行的语句 # 也可以在 demo.sh 中加上 set -x bash -x demo.sh 设置环境变量,然后通过如上方式运 ...
- SPOJ 1811 LCS - Longest Common Substring
思路 和SPOJ 1812 LCS2 - Longest Common Substring II一个思路,改成两个串就有双倍经验了 代码 #include <cstdio> #includ ...
- Cordova 笔记
npm instal -g cordova 安装 卸载cordova npm unistall cordova -g 安装指定版本 npm install -g cordova@ 1.创建应用项目及目 ...