XPathResult: booleanValue property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc booleanValue của giao diện XPathResult trả về giá trị boolean của kết quả khi XPathResult.resultTypeBOOLEAN_TYPE.

Giá trị

Giá trị trả về là giá trị boolean của XPathResult được trả về bởi Document.evaluate().

Ngoại lệ

TYPE_ERR

Trong trường hợp XPathResult.resultType không phải là BOOLEAN_TYPE, một DOMException kiểu TYPE_ERR sẽ được ném ra.

Ví dụ

Ví dụ sau đây cho thấy cách sử dụng thuộc tính booleanValue.

HTML

html
<div>XPath example</div>
<p>Text is 'XPath example': <output></output></p>

JavaScript

js
const xpath = "//div/text() = 'XPath example'";
const result = document.evaluate(
  xpath,
  document,
  null,
  XPathResult.BOOLEAN_TYPE,
  null,
);
document.querySelector("output").textContent = result.booleanValue;

Kết quả

Thông số kỹ thuật

Specification
DOM
# dom-xpathresult-booleanvalue

Tương thích trình duyệt