public interface DOMElement extends DOMNode
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAttribute(java.lang.String name)
Returns an attribute value by
按名称返回属性值。 name .
|
java.util.Map<java.lang.String,java.lang.String> |
getAttributes()
Returns a map that contains attributes of the current element.
返回包含当前元素属性的映射。 |
java.awt.Rectangle |
getBoundingClientRect()
Returns bounds of the element and its position relative to the top-left of the viewport of the current document.
返回元素的边界及其相对于当前文档视口左上角的位置。 |
java.lang.String |
getInnerHTML()
Returns a string that represents inner HTML of the current element.
返回表示当前元素的内部HTML的字符串。 |
java.lang.String |
getInnerText()
Returns the text assigned to the element or empty string when the element cannot contain text (for example, an IMG element).
当元素不能包含文本(例如,IMG元素)时,返回分配给元素的文本或空字符串。 |
boolean |
hasAttribute(java.lang.String name)
Returns
如果在此元素上指定了具有给定名称的属性或具有默认值,则返回true,否则返回false。 true when an attribute with a given name is specified on this element or has a default value,
false otherwise.
|
void |
removeAttribute(java.lang.String name)
Removes an attribute specified by
删除由名称指定的属性。 name .
|
void |
scrollToBottom()
Scrolls the element into the visible area and aligns
bottom of the element to the
bottom of the visible area.
将元素滚动到可见区域,然后将元素的底部与可见区域的底部对齐。 |
void |
scrollToTop()
Scrolls the element into the visible area and aligns
top of the element to the
top of the visible area.
将元素滚动到可见区域,然后将元素的顶部与可见区域的顶部对齐。 |
boolean |
setAttribute(java.lang.String name, java.lang.String value)
Adds a new attribute.
添加一个新属性。 |
boolean |
setInnerHTML(java.lang.String html)
Replaces inner HTML of the current element with specified
用指定的html替换当前元素的内部HTML。 html .
|
boolean |
setInnerText(java.lang.String innerText)
Sets the text assigned to the element.
设置分配给元素的文本。 |
appendChild, click, compareDocumentPosition, getChildren, getNextSibling, getNodeName, getNodeType, getNodeValue, getParent, getParentFrameId, getPreviousSibling, getTextContent, getXPath, insertChild, removeChild, replaceChild, setNodeValue, setTextContent
addEventListener, dispatchEvent, getEventListeners, removeEventListener
evaluate, evaluate, findElement, findElements
java.lang.String getAttribute(java.lang.String name)
name
.
name
- the attribute name.
-属性名称。
java.lang.IllegalArgumentException
- if
name
parameter is
null
or empty.
hasAttribute(String)
boolean setAttribute(java.lang.String name, java.lang.String value)
name
- the name of the attribute to create or alter.
-要创建或更改的属性的名称。
value
- value to set in string form.
-以字符串形式设置的值。
true
when attribute was added successfully.
属性添加成功时。
java.lang.IllegalArgumentException
- if
name
or
value
parameter is
null
or empty.
void removeAttribute(java.lang.String name)
name
.
name
- the name of the attribute to remove.
-要删除的属性的名称。
java.lang.IllegalArgumentException
- if
name
parameter is
null
or empty.
boolean hasAttribute(java.lang.String name)
true
when an attribute with a given name is specified on this element or has a default value,
false
otherwise.
name
- the name of the attribute to look for.
-要查找的属性的名称。
true
if an attribute with the given name is specified on this element or has a default value,
false
otherwise.
如果在此元素上指定了具有给定名称的属性或具有默认值,则为否则。
java.lang.IllegalArgumentException
- if
name
parameter is
null
or empty.
java.util.Map<java.lang.String,java.lang.String> getAttributes()
java.lang.String getInnerHTML()
boolean setInnerHTML(java.lang.String html)
html
.
html
- a new inner HTML of the current element.
-当前元素的新内部HTML。
true
when HTML code of the current element was replaced successfully.
成功替换当前元素的HTML代码时。
java.lang.String getInnerText()
DOMNode.getTextContent()
,
getInnerHTML()
boolean setInnerText(java.lang.String innerText)
InnerText
, the HTML code will display as literals in the document, just as if you were viewing HTML within a text file. If you assign HTML to an element using the
InnerHTML
property,
InnerText
will return all of the text in that HTML with the markup removed.
Assigning a value to
InnerText
will destroy any child elements that belong to the element.
innerText
- the element's text, absent any HTML markup. If the element contains child elements, only the text in those child elements will be preserved.
-元素的文本,没有任何HTML标记。如果元素包含子元素,则仅保留那些子元素中的文本。
true
when the element's text was set successfully, otherwise -
false
when the element cannot contain text (for example, an IMG element).
成功设置元素的文本时;否则-当元素不能包含文本时(例如,IMG元素)。
DOMNode.setTextContent(String)
,
setInnerHTML(String)
java.awt.Rectangle getBoundingClientRect()
The amount of scrolling that has been done of the viewport area (or any other scrollable element) is taken into account when computing the bounding rectangle. This means that the rectangle's boundary edges (top, left, bottom, and right) change their values every time the scrolling position changes (because their values are relative to the viewport and not absolute). If you need the bounding rectangle relative to the top-left corner of the document, just add the current scrolling position to the top and left properties (these can be obtained using window.scrollX
and window.scrollY
) to get a bounding rectangle which is independent from the current scrolling position.
void scrollToTop()
void scrollToBottom()