命名空间 dom
Defined in: jx.dom.js.
Constructor Attributes | Constructor Name and Description |
---|---|
dom 名字空间
|
Method Attributes | Method Name and Description |
---|---|
<static> |
dom.addClass(el, className)
给元素添加 class
|
<static> |
dom.addCssText(el, cssText)
给元素添加cssText
|
<static> |
dom.contains(parent, child, containSelf)
判断一个节点是否是某个父节点的子节点,
默认不包含parent === child的情况
|
<static> |
dom.createStyleNode(样式内容,支持string和object, id)
创建 style 标签
|
<static> |
dom.getAttributeByParent(element, startNode, topNode)
从起始元素查找某个属性,直到找到,或者到达顶层元素位置
Returns the text content of the HTMLElement.
|
<static> |
dom.getClass(el, className)
获取元素的class属性
|
<static> |
dom.getClientHeight(el)
获取当前视窗的高度
Returns the current height of the viewport.
|
<static> |
dom.getClientWidth(el)
获取元素的client宽度
Returns the current width of the viewport.
|
<static> |
dom.getClientXY(el)
获取对象坐标
|
<static> |
dom.getCssText(el)
获取元素的cssText
|
<static> |
dom.getDoc(element)
获取元素所属的根文档
|
<static> |
dom.getDocumentElement()
获取DocumentElement
|
<static> |
dom.getHeight(el)
获取高度的简便方法
|
<static> |
dom.getHref(el)
取一个a标签的href的绝对路径
|
<static> |
dom.getOffsetHeight(el)
获取当前视窗的高度
Returns the current height of the viewport.
|
<static> |
dom.getOffsetWidth(el)
获取元素的client宽度
Returns the current width of the viewport.
|
<static> |
dom.getPosX(el)
获取x坐标的简便方法
|
<static> |
dom.getPosY(el)
获取y坐标的简便方法
|
<static> |
dom.getRelativeXY(el, relativeEl)
获取对象相对一个节点的坐标
|
<static> |
dom.getScrollHeight(element)
获取文档的 scroll 高度,即文档的实际高度
Returns the height of the document.
|
<static> |
dom.getScrollLeft(document)
获取当前文档的左边已卷动的宽度
Returns the left scroll value of the document
|
<static> |
dom.getScrollTop(document)
获取当前文档的上边已卷动的宽度
Returns the top scroll value of the document
|
<static> |
dom.getScrollWidth(element)
获取文档的 scroll 宽度,即文档的实际宽度
Returns the width of the document.
|
<static> |
dom.getSelectionText(win)
获取选择的文本
|
<static> |
dom.getStyle(el, styleName)
获取元素的当前实际样式,css 属性需要用驼峰式写法,如:fontFamily
|
<static> |
dom.getText(element)
获取元素中的文本内容
Returns the text content of the HTMLElement.
|
<static> |
dom.getTextFieldSelection(el)
FireFox 下获取 input 或者 textarea 中选中的文字
|
<static> |
dom.getTransform(target, style)
获取CSS3 transform属性的值,或具体的scale等的值
|
<static> |
dom.getWidth(el)
获取宽度的简便方法
|
<static> |
dom.getXY(el)
获取对象坐标
|
<static> |
dom.hasClass(el, className)
判断元素是否含有 class
|
<static> |
dom.hide(el)
隐藏元素
|
<static> |
dom.id(id, doc)
根据 id 获取元素
|
<static> |
dom.isShow(el)
判断元素是否是显示状态
|
<static> |
dom.mini(query)
一个据说比jq还快的筛选器,可以满足日常99%的筛选需要
|
<static> |
dom.name(name, doc)
根据 name 属性获取元素
|
<static> |
dom.node(type, attr, win)
生成一个 DOM 节点
Generates an HTML element, this is not appended to a document
|
<static> |
dom.recover(el)
还原元素原来的display属性
|
<static> |
dom.removeClass(el, className)
给元素移除 class
|
<static> |
dom.replaceClass(el, oldClassName, newClassName)
替换元素 oldClassName 为 newClassName
|
<static> |
dom.setClass(el, className)
设置元素的class属性
|
<static> |
dom.setClientXY(el, x, y)
设置dom坐标
|
<static> |
dom.setCssText(el, cssText)
给元素设置cssText
|
<static> |
dom.setStyle(el, styleName, value)
设置元素的样式,css 属性需要用驼峰式写法,如:fontFamily
|
<static> |
dom.setTransform(target, value, style)
设置元素的transform属性
|
<static> |
dom.setXY(el, x, y)
设置dom坐标
|
<static> |
dom.show(el, displayStyle)
显示元素
|
<static> |
dom.tagName(tagName, doc)
根据 tagName 获取元素
|
<static> |
dom.toggleClass(el, className)
对元素 class 的切换方法,即:如果元素用此class则移除此class,如果没有此class则添加此class
|
方法详解
<static>
dom.addClass(el, className)
- 功能:
- 给元素添加 class
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称
<static>
dom.addCssText(el, cssText)
- 功能:
- 给元素添加cssText
- 参数:
-
- {Element} el
- 元素
- {String} cssText
- css 属性
<static>
{Boolean}
dom.contains(parent, child, containSelf)
- 功能:
- 判断一个节点是否是某个父节点的子节点, 默认不包含parent === child的情况
- 参数:
-
- {HTMLElement} parent
- {HTMLElement} child
- {Boolean} containSelf
- 指示是否包括parent等于child的情况
- 返回:
- {Boolean} 包含则返回true
<static>
dom.createStyleNode(样式内容,支持string和object, id)
- 功能:
- 创建 style 标签
- 参数:
-
- 样式内容,支持string和object
- {String} id
- 样式标签的 id
<static>
{String}
dom.getAttributeByParent(element, startNode, topNode)
- 功能:
- 从起始元素查找某个属性,直到找到,或者到达顶层元素位置 Returns the text content of the HTMLElement.
- 参数:
-
- {HTMLElement} element
- The html element.
- startNode
- topNode
- 返回:
- {String} The text content of the element (includes text of any descending elements).
<static>
dom.getClass(el, className)
- 功能:
- 获取元素的class属性
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称
<static>
{Number}
dom.getClientHeight(el)
- 功能:
- 获取当前视窗的高度 Returns the current height of the viewport.
- 参数:
-
- el
- 返回:
- {Number} The height of the viewable area of the page (excludes scrollbars).
<static>
{Number}
dom.getClientWidth(el)
- 功能:
- 获取元素的client宽度 Returns the current width of the viewport.
- 参数:
-
- {Element} el
- 要获取client宽度的元素
- 返回:
- {Number} 宽度值.
<static>
dom.getClientXY(el)
- 功能:
- 获取对象坐标
- 参数:
-
- {HTMLElement} el
- 返回:
- Array [left,top]
<static>
dom.getCssText(el)
- 功能:
- 获取元素的cssText
- 参数:
-
- {Element} el
- 元素
<static>
{HTMLElement}
dom.getDoc(element)
- 功能:
- 获取元素所属的根文档
- 参数:
-
- element
- 返回:
- {HTMLElement} document
<static>
{HTMLElement}
dom.getDocumentElement()
- 功能:
- 获取DocumentElement
- 返回:
- {HTMLElement} documentElement
<static>
{String}
dom.getHeight(el)
- 功能:
- 获取高度的简便方法
- 参数:
-
- {HTMLElement} el
- 返回:
- {String}
<static>
{String}
dom.getHref(el)
- 功能:
- 取一个a标签的href的绝对路径
- 参数:
-
- {HTMLElement} el
- 返回:
- {String} 返回一个完整的url
<static>
{Number}
dom.getOffsetHeight(el)
- 功能:
- 获取当前视窗的高度 Returns the current height of the viewport.
- 参数:
-
- el
- 返回:
- {Number} The height of the viewable area of the page (excludes scrollbars).
<static>
{Number}
dom.getOffsetWidth(el)
- 功能:
- 获取元素的client宽度 Returns the current width of the viewport.
- 参数:
-
- {Element} el
- 要获取client宽度的元素
- 返回:
- {Number} 宽度值.
<static>
{String}
dom.getPosX(el)
- 功能:
- 获取x坐标的简便方法
- 参数:
-
- {HTMLElement} el
- 返回:
- {String}
<static>
{String}
dom.getPosY(el)
- 功能:
- 获取y坐标的简便方法
- 参数:
-
- {HTMLElement} el
- 返回:
- {String}
<static>
dom.getRelativeXY(el, relativeEl)
- 功能:
- 获取对象相对一个节点的坐标
- 参数:
-
- {HTMLElement} el
- {HTMLElement} relativeEl
- 返回:
- Array [top,left]
<static>
{Number}
dom.getScrollHeight(element)
- 功能:
- 获取文档的 scroll 高度,即文档的实际高度 Returns the height of the document.
- 参数:
-
- {HTMLElement} element
- The html element.
- 返回:
- {Number} The height of the actual document (which includes the body and its margin).
<static>
{Number}
dom.getScrollLeft(document)
- 功能:
- 获取当前文档的左边已卷动的宽度 Returns the left scroll value of the document
- 参数:
-
- {HTMLDocument} document
- (optional) The document to get the scroll value of
- 返回:
- {Number} The amount that the document is scrolled to the left
<static>
{Number}
dom.getScrollTop(document)
- 功能:
- 获取当前文档的上边已卷动的宽度 Returns the top scroll value of the document
- 参数:
-
- {HTMLDocument} document
- (optional) The document to get the scroll value of
- 返回:
- {Number} The amount that the document is scrolled to the top
<static>
{Number}
dom.getScrollWidth(element)
- 功能:
- 获取文档的 scroll 宽度,即文档的实际宽度 Returns the width of the document.
- 参数:
-
- {HTMLElement} element
- The html element.
- 返回:
- {Number} The width of the actual document (which includes the body and its margin).
<static>
{String}
dom.getSelectionText(win)
- 功能:
- 获取选择的文本
- 参数:
-
- {Window} win
- 返回:
- {String} 返回选择的文本
<static>
{String}
dom.getStyle(el, styleName)
- 功能:
- 获取元素的当前实际样式,css 属性需要用驼峰式写法,如:fontFamily
- 参数:
-
- {Element} el
- 元素
- {String} styleName
- css 属性名称
- 返回:
- {String} 返回元素样式
<static>
{String}
dom.getText(element)
- 功能:
- 获取元素中的文本内容 Returns the text content of the HTMLElement.
- 参数:
-
- {HTMLElement} element
- The html element.
- 返回:
- {String} The text content of the element (includes text of any descending elements).
<static>
{String}
dom.getTextFieldSelection(el)
- 功能:
- FireFox 下获取 input 或者 textarea 中选中的文字
- 参数:
-
- {HTMLElement} el
- 返回:
- {String} 返回选择的文本
<static>
dom.getTransform(target, style)
- 功能:
- 获取CSS3 transform属性的值,或具体的scale等的值
- 参数:
-
- {element} target
- 要获取属性的元素
- {string} style
- 要获取的属性,如果不指定则默认为transform
<static>
{String}
dom.getWidth(el)
- 功能:
- 获取宽度的简便方法
- 参数:
-
- {HTMLElement} el
- 返回:
- {String}
<static>
dom.getXY(el)
- 功能:
- 获取对象坐标
- 参数:
-
- {HTMLElement} el
- 返回:
- Array [top,left]
<static>
dom.hasClass(el, className)
- 功能:
- 判断元素是否含有 class
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称
<static>
dom.hide(el)
- 功能:
- 隐藏元素
- 参数:
-
- {Element} el
- 元素
<static>
{Element}
dom.id(id, doc)
- 功能:
- 根据 id 获取元素
- 参数:
-
- {String} id
- 元素的 id 名称
- {Element} doc
- 元素所属的文档对象,默认为当前文档
- 返回:
- {Element} 返回元素
<static>
dom.isShow(el)
- 功能:
- 判断元素是否是显示状态
- 参数:
-
- {Element} el
- 元素
<static>
{Element}
dom.mini(query)
- 功能:
-
一个据说比jq还快的筛选器,可以满足日常99%的筛选需要
Defined in: jx.mini.js.
//创建一个匿名package包: Jx().$package(function(J){ //这时上下文对象this指向全局window对象 var lists = J.dom.mini(".list"); };
- 参数:
-
- {String} query
- string 筛选器语法
- 返回:
- {Element} 返回筛选出的dom元素
<static>
{Element}
dom.name(name, doc)
- 功能:
- 根据 name 属性获取元素
- 参数:
-
- {String} name
- 元素的 name 属性
- {Element} doc
- 元素所属的文档对象,默认为当前文档
- 返回:
- {Element} 返回元素
<static>
{HTMLElement}
dom.node(type, attr, win)
- 功能:
- 生成一个 DOM 节点 Generates an HTML element, this is not appended to a document
- 参数:
-
- type
- {string} the type of element
- attr
- {string} the attributes
- win
- {Window} optional window to create the element in
- 返回:
- {HTMLElement} the generated node
<static>
dom.recover(el)
- 功能:
- 还原元素原来的display属性
- 参数:
-
- {Element} el
- 元素
<static>
dom.removeClass(el, className)
- 功能:
- 给元素移除 class
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称
<static>
dom.replaceClass(el, oldClassName, newClassName)
- 功能:
- 替换元素 oldClassName 为 newClassName
- 参数:
-
- {Element} el
- 元素
- {String} oldClassName
- 被替换的 class 名称
- {String} newClassName
- 要替换成的 class 名称
<static>
dom.setClass(el, className)
- 功能:
- 设置元素的class属性
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称
<static>
dom.setClientXY(el, x, y)
- 功能:
- 设置dom坐标
<static>
dom.setCssText(el, cssText)
- 功能:
- 给元素设置cssText
- 参数:
-
- {Element} el
- 元素
- {String} cssText
- css 属性
<static>
dom.setStyle(el, styleName, value)
- 功能:
- 设置元素的样式,css 属性需要用驼峰式写法,如:fontFamily
- 参数:
-
- {Element} el
- 元素
- {String} styleName
- css 属性名称
- {String} value
- css 属性值
<static>
dom.setTransform(target, value, style)
- 功能:
- 设置元素的transform属性
- 参数:
-
- {element} target
- 要设置属性的元素
- {mixed} value
- 属性值,类型视具体属性而定
- {string} style
- 要设置的属性,如果不指定则默认为transform
<static>
dom.setXY(el, x, y)
- 功能:
- 设置dom坐标
<static>
dom.show(el, displayStyle)
- 功能:
- 显示元素
- 参数:
-
- {Element} el
- 元素
- {String} displayStyle
- 强制指定以何种方式显示,如:block,inline,inline-block等等
<static>
{Element}
dom.tagName(tagName, doc)
- 功能:
- 根据 tagName 获取元素
- 参数:
-
- {String} tagName
- 元素的 tagName 标签名
- {Element} doc
- 元素所属的文档对象,默认为当前文档
- 返回:
- {Element} 返回元素
<static>
dom.toggleClass(el, className)
- 功能:
- 对元素 class 的切换方法,即:如果元素用此class则移除此class,如果没有此class则添加此class
- 参数:
-
- {Element} el
- 元素
- {String} className
- class 名称