document封装一些常用的方法
function $(str){
var ind = str.substr(0, 1);
var stx = str.substring(1,str.length);
console.info(ind,stx)
if(ind==='.'){
return document.getElementsByClassName(stx);
}else if(ind==='#'){
return document.getElementById(stx);
}else{
return document.getElementsByTagName(stx);
}
}
/**
* 批量修改元素样式
*/
function css(domObj,styleArry){
for(var i=0;i<styleArry.length;i++){
domObj.style[styleArry[i].key] = styleArry[i].val;
}
}
//调用
css(imgs[0],[
{key:'display',val:'block'},
{key:'width',val:'156px'},
{key:'height',val:'30px'}
]);
上面是批量设置节点样式
//获得屏宽高
function bodyWAndH() {
var data = {
width:document.documentElement.clientWidth,
height:document.documentElement.clientHeight
};
return data;
}
//去掉px
function getPX(str){
return str.substring(0,str.indexOf('px'));
}
document封装一些常用的方法的更多相关文章
- DOM中document对象的常用属性方法
每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问. 属性 1 document.anchors 返 ...
- js基础之DOM中document对象的常用属性方法
-----引入 每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问. 属性 1 document.an ...
- JS常用公共方法封装
_ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||/ ...
- 常用js方法封装
常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...
- appium安卓自动化的 常用driver方法封装
appium安卓自动化的 常用driver方法封装 做安卓自动化的时候,很多方法写起来会造成代码冗余,把这部分封装起来 ,添加到androidUI工具类里,随时可调用 都放在这个类下面: @Compo ...
- python openpyxl 封装Execl常用操作的方法
封装Excel操作方法:先装openpyxl:pip install openpyxl==2.4.5(可以指定版本) 封装脚本:#encoding=utf-8 from openpyxl import ...
- jQuery常用工具方法
前面的话 jQuery提供一些与元素无关的工具方法,不必选中元素,就可以直接使用这些方法.如果理解原生javascript的继承原理,那么就能理解工具方法的实质.它是定义在jQuery构造函数上的方法 ...
- javascript的函数、创建对象、封装、属性和方法、继承
转自原文javascript的函数.创建对象.封装.属性和方法.继承 一,function 从一开始接触到js就感觉好灵活,每个人的写法都不一样,比如一个function就有N种写法 如:functi ...
- WebAPi添加常用扩展方法及思维发散
前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...
随机推荐
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- 为什么要在游戏开发中使用ECS模式
http://www.richardlord.net/blog/why-use-an-entity-framework Why use an entity system framework for g ...
- python优先队列,队列和栈
打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...
- java Fn键
需求分析 我想开机禁用触摸板. 方案设计 安装驱动:比较麻烦,驱动也不一定支持开机禁用触摸板. 编程实现,让一段代码开机禁用触摸板 编程实现也分好几种方法: 使用windows API禁用触摸板,这需 ...
- json的场景应用与实战
首先 要感谢慕课网的老师 地址:http://www.imooc.com/learn/68 下面我来开始总结: 什么是json的这些我就不多说了 不懂百度 <?php function cre ...
- DSO之光度标定
光度标定(Photometric Camera Calibration)是DSO(Direct Sparse Odometry)论文中比较特别的一部分.常规的vSLAM不太考虑光度标定的问题.比如基于 ...
- iOS 组件化漫谈
1.准备工作 由于工程越来越大,里面的文件也越来越多.很多时候merge代码的时候工程文件起了冲突之后,若 .xcodeproj文件冲突 打开之后很难以修改. 架构其实相对开发来说还是比较难于下手的东 ...
- sass接触
第一句话就是棒棒的,我爱上了. 看了真阿当的文章:<2016年前端技术观察> http://weibo.com/ttarticle/p/show?id=230940405256054051 ...