Giao diện CSSStyleDeclaration
đại diện cho một đối tượng là khối khai báo CSS và hiển thị thông tin về kiểu dáng cũng như các phương thức và thuộc tính liên quan đến kiểu dáng khác nhau
Một đối tượng CSSStyleDeclaration
có thể được hiển thị bằng ba API khác nhau
- Thông qua
HTMLElement.style
, giải quyết các kiểu nội tuyến của một phần tử [e. g. ,]
- Thông qua API
CSSStyleSheet
. Ví dụ:document.styleSheets[0].cssRules[0].style
trả về một đối tượngCSSStyleDeclaration
trên quy tắc CSS đầu tiên trong biểu định kiểu đầu tiên của tài liệu - Qua
Window.getComputedStyle[]
, hiển thị đối tượngCSSStyleDeclaration
dưới dạng giao diện chỉ đọc
Giao diện CSSStyleDeclaration
đại diện cho một đối tượng là khối khai báo CSS và hiển thị thông tin về kiểu dáng cũng như các phương thức và thuộc tính liên quan đến kiểu dáng khác nhau
Một đối tượng CSSStyleDeclaration
có thể được hiển thị bằng ba API khác nhau
- Thông qua
HTMLElement.style
, giải quyết các kiểu nội tuyến của một phần tử [e. g. ,object.parentRule
3] - Thông qua API
CSSStyleSheet
. Ví dụ:document.styleSheets[0].cssRules[0].style
trả về một đối tượngCSSStyleDeclaration
trên quy tắc CSS đầu tiên trong biểu định kiểu đầu tiên của tài liệu - Qua
Window.getComputedStyle[]
, hiển thị đối tượngCSSStyleDeclaration
dưới dạng giao diện chỉ đọc
Thuộc tính
CSSStyleDeclaration
0Biểu diễn văn bản của khối khai báo. Đặt thuộc tính này sẽ thay đổi kiểu. CSSStyleDeclaration
1 Chỉ đọc Số lượng thuộc tính. Xem phương pháp CSSStyleDeclaration
2 bên dưới. CSSStyleDeclaration
3 Chỉ đọcChứa CSSStyleDeclaration
4Thuộc tính CSS
CSSStyleDeclaration
5 Bí danh đặc biệt cho thuộc tính CSS CSSStyleDeclaration
6. CSSStyleDeclaration
thuộc tính có tênDashed và thuộc tính vỏ lạc đà cho tất cả các thuộc tính CSS được hỗ trợphương pháp
CSSStyleDeclaration
8Trả về mức độ ưu tiên tùy chọn, "quan trọng". CSSStyleDeclaration
9Trả về giá trị thuộc tính cho một tên thuộc tính. CSSStyleDeclaration
0Trả về tên thuộc tính CSS theo chỉ mục của nó hoặc chuỗi trống nếu chỉ mục nằm ngoài giới hạn. Một cách thay thế để truy cập CSSStyleDeclaration
1 [thay vào đó trả về CSSStyleDeclaration
2 khi CSSStyleDeclaration
3 vượt quá giới hạn]. Điều này chủ yếu hữu ích cho việc triển khai DOM không phải JavaScript. CSSStyleDeclaration
4Xóa thuộc tính khỏi khối khai báo CSS. CSSStyleDeclaration
5Sửa đổi thuộc tính CSS hiện có hoặc tạo thuộc tính CSS mới trong khối khai báo. CSSStyleDeclaration
6 Chỉ được hỗ trợ qua getComputingStyle trong Firefox. Trả về giá trị thuộc tính dưới dạng CSSStyleDeclaration
7 hoặc CSSStyleDeclaration
8 cho thuộc tính tốc kýThí dụ
var styleObj = document.styleSheets[0].cssRules[0].style; console.log[styleObj.cssText]; for [var i = styleObj.length; i--;] { var nameString = styleObj[i]; styleObj.removeProperty[nameString]; } console.log[styleObj.cssText];
thông số kỹ thuật
SpecificationStatusComment Bản thảo làm việc Đã hợp nhất giao diệnCSSStyleDeclaration
9 Kiểu DOM Cấp 2 thành CSSStyleDeclaration
. Lỗi thờiđịnh nghĩa ban đầuTính tương thích của trình duyệt web
Bảng tương thích trong trang này được tạo từ dữ liệu có cấu trúc. Nếu bạn muốn đóng góp cho dữ liệu, vui lòng xem https. //github. com/mdn/browser-compat-data và gửi yêu cầu kéo cho chúng tôi
Thuộc tính parentRule được sử dụng để trả về Đối tượng CSSRule đại diện cho bộ quy tắc CSS có chứa bộ chọn và khối khai báo.
cú pháp. Nó được sử dụng để trả về thuộc tính parentRule
object.parentRule
Giá trị trả về. Nó trả về đối tượng CSSRule.
Thí dụ. Để trả về thuộc tính parentRule.
html
HTMLElement.style
0HTMLElement.style
1HTMLElement.style
2
HTMLElement.style
0HTMLElement.style
4HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____48HTMLElement.style
2
HTMLElement.style
01HTMLElement.style
02
HTMLElement.style
6HTMLElement.style
04HTMLElement.style
8HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____409HTMLElement.style
2
HTMLElement.style
01HTMLElement.style
12
HTMLElement.style
13HTMLElement.style
14
_______401____416
HTMLElement.style
01
HTMLElement.style
01HTMLElement.style
19
HTMLElement.style
13HTMLElement.style
21
_______401____416
HTMLElement.style
01
HTMLElement.style
01HTMLElement.style
26
HTMLElement.style
13HTMLElement.style
21
HTMLElement.style
13HTMLElement.style
00
_______401____416
HTMLElement.style
6HTMLElement.style
04HTMLElement.style
09HTMLElement.style
2
HTMLElement.style
04HTMLElement.style
4HTMLElement.style
2
HTMLElement.style
0HTMLElement.style
41HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____445HTMLElement.style
2
HTMLElement.style
47HTMLElement.style
48
HTMLElement.style
49HTMLElement.style
04HTMLElement.style
45HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____425 HTMLElement.style
26
HTMLElement.style
47HTMLElement.style
28
HTMLElement.style
49HTMLElement.style
04HTMLElement.style
25HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____425HTMLElement.style
2
HTMLElement.style
47HTMLElement.style
68
HTMLElement.style
47HTMLElement.style
00
HTMLElement.style
49HTMLElement.style
04HTMLElement.style
25HTMLElement.style
2
HTMLElement.style
6HTMLElement.style
0____407 HTMLElement.style
08
HTMLElement.style
01HTMLElement.style
80
HTMLElement.style
6HTMLElement.style
04HTMLElement.style
07HTMLElement.style
2
HTMLElement.style
6 ________ 40HTMLElement.style
25 ________ 488HTMLElement.style
25 ________ 42
HTMLElement.style
6HTMLElement.style
002
HTMLElement.style
6HTMLElement.style
0____4005HTMLElement.style
2
_______401____4008
_______413____4010
________ 4011 ________ 4012
HTMLElement.style
013HTMLElement.style
014
HTMLElement.style
13HTMLElement.style
016
_______401____416
HTMLElement.style
6HTMLElement.style
04HTMLElement.style
005HTMLElement.style
2
HTMLElement.style
04HTMLElement.style
41HTMLElement.style
2
HTMLElement.style
04HTMLElement.style
1HTMLElement.style
2
đầu ra
- Trước khi bấm vào nút
- Sau khi nhấp vào nút
Trình duyệt được hỗ trợ. Các trình duyệt được Thuộc tính parentRule của Khai báo Kiểu hỗ trợ được liệt kê bên dưới