{"id":2378,"date":"2012-05-08T23:31:32","date_gmt":"2012-05-08T15:31:32","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378"},"modified":"2018-07-24T11:07:17","modified_gmt":"2018-07-24T03:07:17","slug":"getcomputedstyle-js-getpropertyvalue-currentstyle","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2012\/05\/getcomputedstyle-js-getpropertyvalue-currentstyle\/","title":{"rendered":"\u83b7\u53d6\u5143\u7d20CSS\u503c\u4e4bgetComputedStyle\u65b9\u6cd5\u719f\u6089"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378<\/a><\/p>\n<h3>\u4e00\u3001\u788e\u788e\u5ff5~\u524d\u8a00<\/h3>\n<p>\u6211\u4eec\u90fd\u7528\u8fc7jQuery\u7684<code>CSS()<\/code>\u65b9\u6cd5\uff0c\u5176\u5e95\u5c42\u8fd0\u4f5c\u5c31\u5e94\u7528\u4e86getComputedStyle\u4ee5\u53cagetPropertyValue\u65b9\u6cd5\u3002<\/p>\n<p>\u5bf9\u4e8e\u90a3\u4e9b\u53ea\u60f3\u6df7\u53e3\u996d\u5403\u7684\u4eba\u6765\u8bb2\uff0c\u6653\u5f97<code>CSS()<\/code>\u5982\u4f55\u4f7f\u7528\u5c31\u8db3\u591f\u4e86\u3002\u5bf9\u4e8e\u5e0c\u671b\u5728JS\u9053\u8def\u4e0a\u8d8a\u8d70\u8d8a\u8fdc\u7684\u6765\u4eba\u8bf4\uff0c\u7b80\u5355\u4e86\u89e3\u4e00\u4e9bJS\u5e93\u5e95\u5c42\u5b9e\u73b0\u5bf9\u81ea\u5df1\u7684\u5b66\u4e60\u5f88\u6709\u5e2e\u52a9\u3002\u53ef\u80fd\u8c08\u4e0d\u4e0a\u4fe1\u624b\u62c8\u6765\u7684\u4f7f\u7528\uff0c\u81f3\u5c11\u5bf9\u521b\u9020\u4e00\u4e9b\u521b\u610f\u65b0\u9896\u7684\u65b0\u6280\u672f\u62d3\u5bbd\u4e86\u601d\u8def\u3002<\/p>\n<p>jQuery\u4e3a\u4f55\u53d7\u6b22\u8fce\uff0c\u5176\u4e2d\u539f\u56e0\u4e4b\u4e00\u5c31\u662f\u65b9\u6cd5\u540d\u79f0\u6bd4\u8f83\u77ed\u3002\u597d\u6bd4\u6253\u67b6\u4e00\u6837\uff0c\u5757\u5934\u5927\u7684\u6f5c\u610f\u8bc6\u8ba4\u4e3a\u5389\u5bb3\uff0c\u5c31\u4e0d\u7531\u5f97\u5fc3\u751f\u754f\u60e7\uff0c\u9000\u907f\u4e09\u820d\uff1b\u5c0f\u4e2a\u5b50\uff08\u6216\u6751\u5987\uff0c\u5c0f\u5b69\uff09\u561b\uff0c\u81ea\u7136\u4ee5\u4e3a\u662f\u8f6f\u8c46\u8150\uff0c\u613f\u610f\u63a5\u53d7\u4f5c\u4e3a\u5bf9\u624b\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\u529f\u592b\u5267\u7167 \u5468\u661f\u9a70\u88ab\u6751\u5987K \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_194924.jpg\" title=\"\u529f\u592b\u5267\u7167 \u5468\u661f\u9a70\u88ab\u6751\u5987K\" class=\"alignnone\" width=\"407\" height=\"306\" \/> <img loading=\"lazy\" decoding=\"async\" alt=\"\u529f\u592b\u5267\u7167 \u5468\u661f\u9a70\u627e\u5c0f\u5b69\u5355\u6311 \u7ed3\u679c\u2026\u2026 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_195035.jpg\" title=\"\u529f\u592b\u5267\u7167 \u5468\u661f\u9a70\u627e\u5c0f\u5b69\u5355\u6311 \u7ed3\u679c\u2026\u2026\" class=\"alignnone\" width=\"369\" height=\"286\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u5f53\u770b\u5230\u7c7b\u4f3c<code>getComputedStyle<\/code>\u8fd9\u4e48\u957f\u7684\u65b9\u6cd5\u540d\u7684\u65f6\u5019\uff0c\u6211\u4eec\u8eab\u4f53\u91cc\u90a3\u4e2a\u61d2\u60f0\u5c0f\u4eba\u7a81\u7136\u5c31\u9192\u4e86\uff1a\u54ce\u54df\u54df\uff0c\u8fd9\u4e1c\u897f\uff0c\u5c31\u8ddf\u653e\u5fc3\u98df\u54c1\u4e00\u6837\uff0c\u51e0\u5e74\u624d\u89c1\u4e00\u56de\u3002\u770b\u4e0a\u53bb\u53c8\u86ee\u590d\u6742\uff0c\u60f3\u5230\u665a\u4e0a\u8fd8\u8981\u8ddf\u59b9\u5b50\u804a\u5929\u3002\u8fd9\u4e1c\u897f\uff0c\u5c31\u8ba9\u5b83\u4ece\u65c1\u8fb9\u8fc7\u5427\uff0c\u53cd\u6b63\u4e0d\u4f1a\u6389\u5757\u8089\u7684\u3002<\/p>\n<p>\u7f51\u4e0a\u4e0d\u662f\u6709\u8fd9\u4e48\u4e2a\u6bb5\u5b50\u561b\uff1a<strong>\u53ef\u6015\u7684\u662f\uff0c\u6bd4\u4f60\u806a\u660e\u7684\u4eba\u6bd4\u4f60\u66f4\u52e4\u594b<\/strong>\u3002\u90a3\u4e48\uff0c\u8fd9\u91cc\u7684\u201c\u52e4\u594b\u201d\u7684\u5dee\u5f02\u4f53\u73b0\u5728\u4ec0\u4e48\u5730\u65b9\u5462\uff1f\u5c31\u62ff\u8fd9\u4e2a<code>getComputedStyle<\/code>\u4e3e\u4f8b\uff1a\u61d2\u60f0\u9752\u5e74\u662f\u770b\u4e00\u4e0b\uff0c\u7acb\u9a6c\u50cf\u770b\u89c1\u51e4\u59d0\u4e00\u6837\u89c6\u7ebf\u79bb\u5f00\uff1b\u666e\u901a\u9752\u5e74\u662f\u770b\u4e00\u4e0b\uff0c\u53d1\u73b0\u81ea\u5df1\u4e0d\u4e86\u89e3\uff0c\u767e\u4e00\u4e0b\u6216\u8c37\u4e00\u4e0b\uff0c\u719f\u6089\u4e86\u89e3\u4e4b\uff1b\u52e4\u594b\u9752\u5e74\u662f\u4e0d\u4ec5\u4e86\u89e3\uff0c\u8fd8\u62bd\u51fa\u65f6\u95f4\u5b9e\u8df5\u4e4b\uff08\u5982\u505a\u4e2a\u7b80\u5355demo\u6d4b\u8bd5\uff09\uff0c\u719f\u6089\u65b9\u6cd5\u7684\u7279\u5f02\u6027\uff0c\u9a8c\u8bc1\u4e00\u4e9b\u89c2\u70b9\u6b63\u786e\u6027\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u6309\u7167\u4f60\u73b0\u5728\u7684\u5fc3\u7406\u72b6\u6001\u770b\u770b\u4f60\u662f\u54ea\u7c7b\u9752\u5e74\uff1a\u5982\u679c\u6b64\u65f6\uff0c\u60a8\u5df2\u7ecf\u5bf9\u672c\u6587\u7684\u5185\u5bb9\u6ca1\u6709\u5174\u8da3\u4e86\uff08\u5f53\u7136\uff0c\u60a8\u7684\u5de5\u4f5c\u4e0eJS\u5173\u7cfb\u4eb2\u5bc6\uff09\uff0c\u60a8\u662f\u2026\u2026\uff08\u4f60\u61c2\u7684\uff09\uff1b\u5982\u679c\u60a8\u770b\u5b8c\u672c\u6587\u5185\u5bb9\uff0c\u53d1\u73b0\uff0c\u8fd8\u662f\u6709\u4e0d\u5c11\u6536\u83b7\uff0c\u5fc3\u4e2d\u56de\u5473\u4e0b\uff0c\u7136\u540ectrl+w\u53bb\u5176\u4ed6\u5730\u65b9\u89c5\u98df\uff0c\u4e0d\u518d\u56de\u6765\uff0c\u90a3\u60a8\u662f\u666e\u901a\u9752\u5e74\uff1b\u5982\u679c\u60a8\u770b\u5b8c\u672c\u6587\uff0c\u7136\u540e\u5bf9\u6240\u8bf4\u7684\u4e00\u4e9b\u5185\u5bb9\u4f5c\u4e86\u989d\u5916\u7684\u6d4b\u8bd5\uff0c\u4f8b\u5982IE9\u6d4f\u89c8\u5668\u662f\u5426\u652f\u6301\u6d4b\u8bd5\u7b49\uff0c\u5e76\u901a\u8fc7\u8bc4\u8bba\u5f62\u5f0f\u6307\u51fa\u53ef\u80fd\u7684\u9519\u8bef\uff0c\u4e0d\u5f97\u4e0d\u8bf4\u60a8\u662f\u52e4\u594b\u9752\u5e74\uff0c\u5047\u4ee5\u65f6\u65e5\uff0c\u5fc5\u6709\u4e00\u756a\u6280\u672f\u4f5c\u4e3a\u3002\u4ece\u6211\u6587\u7ae0\u7684\u4e9b\u8bc4\u8bba\u6765\u770b\uff0c\u6709\u4e0d\u5c11\u540c\u884c\u5c31\u662f\u8fd9\u6837\u7684\u52e4\u594b\u4eba\u513f\u3002<\/p>\n<p> \u306e, \u597d\u4e45\u6ca1\u5199\u6587\u7ae0\uff0c\u8bdd\u53c8\u591a\u4e86\uff0c\u6253\u4f4f\uff0c\u8fdb\u5165\u6b63\u9898\u3002<\/p>\n<h3>\u4e8c\u3001getComputedStyle\u662f\uff1f<\/h3>\n<p><code>getComputedStyle<\/code>\u662f\u4e00\u4e2a\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u5143\u7d20\u6240\u6709\u6700\u7ec8\u4f7f\u7528\u7684CSS\u5c5e\u6027\u503c\u3002\u8fd4\u56de\u7684\u662f\u4e00\u4e2aCSS\u6837\u5f0f\u58f0\u660e\u5bf9\u8c61([object CSSStyleDeclaration])\uff0c\u53ea\u8bfb\u3002<\/p>\n<blockquote><p><code>getComputedStyle()<\/code> gives the final used values of all the CSS properties of an element.<\/p><\/blockquote>\n<p><strong>\u8bed\u6cd5<\/strong>\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var style = window.getComputedStyle(\"\u5143\u7d20\", \"\u4f2a\u7c7b\");<\/pre>\n<\/div>\n<p>\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var dom = document.getElementById(\"test\"),\n    style = window.getComputedStyle(dom , \":after\");<\/pre>\n<\/div>\n<p>\u5c31\u4e24\u4e2a\u53c2\u6570\uff0c\u5927\u5bb6\u90fd\u61c2\u4e2d\u6587\u7684\uff0c\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684\u3002\u53ea\u662f\u989d\u5916\u63d0\u793a\u4e0b\uff1aGecko 2.0 (Firefox 4 \/ Thunderbird 3.3 \/ SeaMonkey 2.1) \u4e4b\u524d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u201c\u4f2a\u7c7b\u201d\u662f\u5fc5\u9700\u7684\uff08\u5982\u679c\u4e0d\u662f\u4f2a\u7c7b\uff0c\u8bbe\u7f6e\u4e3a<code>null<\/code>\uff09\uff0c\u4e0d\u8fc7\u73b0\u5728\u561b\uff0c\u4e0d\u662f\u5fc5\u9700\u53c2\u6570\u4e86\u3002<\/p>\n<h3>\u4e09\u3001getComputedStyle\u4e0estyle\u7684\u533a\u522b<\/h3>\n<p>\u6211\u4eec\u4f7f\u7528<code>element.style<\/code>\u4e5f\u53ef\u4ee5\u83b7\u53d6\u5143\u7d20\u7684CSS\u6837\u5f0f\u58f0\u660e\u5bf9\u8c61\uff0c\u4f46\u662f\u5176\u4e0e<code>getComputedStyle<\/code>\u65b9\u6cd5\u8fd8\u6709\u6709\u4e00\u4e9b\u5dee\u5f02\u7684\u3002<\/p>\n<ol>\n<li><strong>\u53ea\u8bfb\u4e0e\u53ef\u5199<\/strong><br \/>\n\u6b63\u5982\u4e0a\u9762\u63d0\u5230\u7684<code>getComputedStyle<\/code>\u65b9\u6cd5\u662f\u53ea\u8bfb\u7684\uff0c\u53ea\u80fd\u83b7\u53d6\u6837\u5f0f\uff0c\u4e0d\u80fd\u8bbe\u7f6e\uff1b\u800c<code>element.style<\/code>\u80fd\u8bfb\u80fd\u5199\uff0c\u80fd\u5c48\u80fd\u4f38\u3002<\/li>\n<li><strong>\u83b7\u53d6\u7684\u5bf9\u8c61\u8303\u56f4<\/strong><br \/>\n<code>getComputedStyle<\/code>\u65b9\u6cd5\u83b7\u53d6\u7684\u662f\u6700\u7ec8\u5e94\u7528\u5728\u5143\u7d20\u4e0a\u7684\u6240\u6709CSS\u5c5e\u6027\u5bf9\u8c61\uff08\u5373\u4f7f\u6ca1\u6709CSS\u4ee3\u7801\uff0c\u4e5f\u4f1a\u628a\u9ed8\u8ba4\u7684\u7956\u5b97\u516b\u4ee3\u90fd\u663e\u793a\u51fa\u6765\uff09\uff1b\u800c<code>element.style<\/code>\u53ea\u80fd\u83b7\u53d6\u5143\u7d20<code>style<\/code>\u5c5e\u6027\u4e2d\u7684CSS\u6837\u5f0f\u3002\u56e0\u6b64\u5bf9\u4e8e\u4e00\u4e2a\u5149\u79c3\u79c3\u7684\u5143\u7d20<code>&lt;p><\/code>\uff0c<code>getComputedStyle<\/code>\u65b9\u6cd5\u8fd4\u56de\u5bf9\u8c61\u4e2d<code>length<\/code>\u5c5e\u6027\u503c\uff08\u5982\u679c\u6709\uff09\u5c31\u662f<code>190+<\/code>(\u636e\u6211\u6d4b\u8bd5FF:192, IE9:195, Chrome:253, \u4e0d\u540c\u73af\u5883\u7ed3\u679c\u53ef\u80fd\u6709\u5dee\u5f02), \u800c<code>element.style<\/code>\u5c31\u662f<code>0<\/code>\u3002<\/li>\n<\/ol>\n<h3>\u56db\u3001getComputedStyle\u4e0edefaultView<\/h3>\n<p>\u5982\u679c\u6211\u4eec\u67e5\u770bjQuery\u6e90\u4ee3\u7801\uff0c\u4f1a\u53d1\u73b0\uff0c\u5176<code>css()<\/code>\u65b9\u6cd5\u5b9e\u73b0\u4e0d\u662f\u4f7f\u7528\u7684<code>window.getComputedStyle<\/code>\u800c\u662f<code>document.defaultView.getComputedStyle<\/code>\uff0c\u5537\uff1f\u8fd9\u662f\u600e\u4e48\u4e00\u56de\u4e8b\uff1f<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"jQuery\u6e90\u7801\u4f7f\u7528document.defaultView.getComputedStyle\u622a\u56fe\u8bc1\u660e\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_211408.png\" title=\"jQuery\u6e90\u7801\u4f7f\u7528document.defaultView.getComputedStyle\u622a\u56fe\u8bc1\u660e\" class=\"alignnone\" width=\"594\" height=\"166\" \/><\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u4f7f\u7528<code>defaultView<\/code>\u57fa\u672c\u4e0a\u662f\u6ca1\u6709\u5fc5\u8981\u7684\uff0c<code>getComputedStyle<\/code>\u672c\u8eab\u5c31\u5b58\u5728<code>window<\/code>\u5bf9\u8c61\u4e4b\u4e2d\u3002\u6839\u636e<a href=\"https:\/\/developer.mozilla.org\/User:DennisHall\">DennisHall<\/a>\u7684\u8bf4\u6cd5\uff0c\u4f7f\u7528<code>defaultView<\/code>\u53ef\u80fd\u4e00\u662f\u4eba\u4eec\u4e0d\u592a\u4e50\u610f\u5728window\u4e0a\u4e13\u95e8\u5199\u4e2a\u4e1c\u897f\uff0c\u4e8c\u662f\u8ba9API\u5728Java\u4e2d\u4e5f\u53ef\u7528\uff08\u8fd9\u6211\u4e0d\u61c2\uff0c\u5fd8\u6307\u70b9~~\uff09\u3002<\/p>\n<p>\u4e0d\u8fc7\u6709\u4e2a\u7279\u6b8a\u60c5\u51b5\uff0c\u5728FireFox3.6\u4e0a\u4e0d\u4f7f\u7528<code>defaultView<\/code>\u65b9\u6cd5\u5c31\u641e\u4e0d\u5b9a\u7684\uff0c\u5c31\u662f<a href=\"https:\/\/github.com\/jquery\/jquery\/pull\/524\">\u8bbf\u95ee\u6846\u67b6(frame)\u7684\u6837\u5f0f<\/a>.<\/p>\n<div class=\"hidden\"><em>\u5982\u679c\u60a8\u770b\u5230\u4e0b\u9762\u7684\u6587\u5b57\uff0c\u53ef\u80fd\u662f\u7531\u4e8e\u5728\u5176\u4ed6\u7f51\u7ad9\u6216\u662fRSS\u4e2d\u9605\u8bfb\u672c\u6587\uff0c\u672c\u6587\u539f\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378<\/a>\uff0c\u672c\u6587\u4f5c\u8005\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed<\/a>\uff0c\u6765\u81ea\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\uff0c\u8bbf\u95ee\u539f\u51fa\u5904\u9605\u8bfb\u4f53\u9a8c\u66f4\u4f73\u3002<\/em><\/div>\n<h3>\u4e94\u3001getComputedStyle\u517c\u5bb9\u6027<\/h3>\n<p>\u5bf9\u4e8e\u684c\u9762\u8bbe\u5907\uff1a<\/p>\n<table class=\"params_table\">\n<tbody>\n<tr>\n<th>&nbsp;<\/th>\n<th>Chrome<\/th>\n<th>Firefox (Gecko)<\/th>\n<th>Internet Explorer<\/th>\n<th>Opera<\/th>\n<th>Safari<\/th>\n<\/tr>\n<tr>\n<td>\u57fa\u672c\u652f\u6301<\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td>9<\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<\/tr>\n<tr>\n<td>\u4f2a\u7c7b\u5143\u7d20\u652f\u6301<\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u4e0d\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/error.gif\" alt=\"\u4e0d\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u4e0d\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/error.gif\" alt=\"\u4e0d\u652f\u6301\" \/><\/span> <\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span> <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5bf9\u4e8e\u624b\u673a\u8bbe\u5907\uff1a<\/p>\n<table class=\"params_table\">\n<tbody>\n<tr>\n<th>&nbsp;<\/th>\n<th>Android<\/th>\n<th>Firefox Mobile (Gecko)<\/th>\n<th>IE Mobile<\/th>\n<th>Opera Mobile<\/th>\n<th>Safari Mobile<\/th>\n<\/tr>\n<tr>\n<td>\u57fa\u672c\u652f\u6301<\/td>\n<td><span title=\"\u6700\u65b0\u7248\u672c\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u6700\u65b0\u7248\u672c\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td>WP7 Mango<\/td>\n<td><span title=\"\u6700\u65b0\u7248\u672c\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u6700\u65b0\u7248\u672c\u652f\u6301\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<\/tr>\n<tr>\n<td>\u4f2a\u5143\u7d20\u652f\u6301<\/td>\n<td><span style=\"color: rgb(255, 153, 0);\" title=\"\u517c\u5bb9\u6027\u672a\u77e5\uff0c\u6709\u52b3\u66f4\u65b0\">?<\/span><\/td>\n<td><span style=\"color: rgb(255, 153, 0);\" title=\"\u517c\u5bb9\u6027\u672a\u77e5\uff0c\u6709\u52b3\u66f4\u65b0\">?<\/span><\/td>\n<td><span title=\"Not supported.\" style=\"color: rgb(255, 0, 0);\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/error.gif\" alt=\"\u4e0d\u652f\u6301\" \/><\/span><\/td>\n<td><span style=\"color: rgb(255, 153, 0);\" title=\"\u517c\u5bb9\u6027\u672a\u77e5\uff0c\u6709\u52b3\u66f4\u65b0\">?<\/span><\/td>\n<td><span style=\"color: rgb(255, 153, 0);\" title=\"\u517c\u5bb9\u6027\u672a\u77e5\uff0c\u6709\u52b3\u66f4\u65b0\">?<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e0a\u9762\u6253\u95ee\u53f7\u7684\u8868\u793a\u6ca1\u6709\u6d4b\u8bd5\uff0c\u662f\u5426\u517c\u5bb9\u4e0d\u77e5\u3002\u5982\u679c\u60a8\u65b9\u4fbf\u6d4b\u8bd5\uff0c\u6b22\u8fce\u5c06\u6d4b\u8bd5\u7ed3\u679c\u544a\u77e5\uff0c\u8fd9\u91cc\u5c06\u53ca\u65f6\u66f4\u65b0\uff0c\u5e76\u9644\u4e0a\u60a8\u7684\u59d3\u540d\uff0c\u4ee5\u8c22\u60a8\u505a\u7684\u8d21\u732e\u3002<\/p>\n<p>\u6211\u4eec\u5148\u628a\u6ce8\u610f\u529b\u653e\u5728\u684c\u9762\u8bbe\u5907\u4e0a\uff0c\u53ef\u4ee5\u770b\u5230\uff0c<code>getComputedStyle<\/code>\u65b9\u6cd5IE6~8\u662f\u4e0d\u652f\u6301\u7684\uff0c\u5f97\uff0c\u80cc\u4e86\u534a\u5929\u7684\u5ab3\u5987\uff0c\u53d1\u73b0\u662f\u5b59\u609f\u7a7a\u53d8\u7684\u2014\u2014\u90c1\u95f7\u4e86\u3002\u4e0d\u6025\uff0cIE\u81ea\u6709\u81ea\u5df1\u7684\u4e00\u5957\u4e1c\u897f\u3002<\/p>\n<h3>\u516d\u3001getComputedStyle\u4e0ecurrentStyle<\/h3>\n<p><code>currentStyle<\/code>\u662fIE\u6d4f\u89c8\u5668\u81ea\u5a31\u81ea\u4e50\u7684\u4e00\u4e2a\u5c5e\u6027\uff0c\u5176\u4e0e<code>element.style<\/code>\u53ef\u4ee5\u8bf4\u662f\u8fd1\u4eb2\uff0c\u81f3\u5c11\u5728\u4f7f\u7528\u5f62\u5f0f\u4e0a\u7c7b\u4f3c\uff0c<code>element.currentStyle<\/code>\uff0c\u5dee\u522b\u5728\u4e8e<code>element.currentStyle<\/code>\u8fd4\u56de\u7684\u662f\u5143\u7d20\u5f53\u524d\u5e94\u7528\u7684\u6700\u7ec8CSS\u5c5e\u6027\u503c\uff08\u5305\u62ec\u5916\u94feCSS\u6587\u4ef6\uff0c\u9875\u9762\u4e2d\u5d4c\u5165\u7684<code>&lt;style&gt;<\/code>\u5c5e\u6027\u7b49\uff09\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4ece\u4f5c\u7528\u4e0a\u5c06\uff0c<code>getComputedStyle<\/code>\u65b9\u6cd5\u4e0e<code>currentStyle<\/code>\u5c5e\u6027\u8d70\u7684\u5f88\u8fd1\uff0c\u5f62\u5f0f\u4e0a\u5219<code>style<\/code>\u4e0e<code>currentStyle<\/code>\u8d70\u7684\u8fd1\u3002\u4e0d\u8fc7\uff0c<code>currentStyle<\/code>\u5c5e\u6027\u8c8c\u4f3c\u4e0d\u652f\u6301\u4f2a\u7c7b\u6837\u5f0f\u83b7\u53d6\uff0c\u8fd9\u662f\u4e0e<code>getComputedStyle<\/code>\u65b9\u6cd5\u7684\u5dee\u5f02\uff0c\u4e5f\u662fjQuery <code>css()<\/code>\u65b9\u6cd5\u65e0\u6cd5\u4f53\u73b0\u7684\u4e00\u70b9\u3002<\/p>\n<p><span class=\"s\">\/\/zxx: \u5982\u679c\u4f60\u53ea\u77e5jQuery css()\u65b9\u6cd5\uff0c\u4f60\u662f\u4e0d\u4f1a\u77e5\u9053\u4f2a\u7c7b\u6837\u5f0f\u4e5f\u662f\u53ef\u4ee5\u83b7\u53d6\u7684\uff0c\u867d\u7136\u90e8\u5206\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u3002<\/span><\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u8981\u83b7\u53d6\u4e00\u4e2a\u5143\u7d20\u7684\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u7c7b\u4f3c\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>alert((element.currentStyle? element.currentStyle : window.getComputedStyle(element, null)).height);<\/pre>\n<\/div>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201205\/currentstyle-getcomputedstyle-element-height.html\">\u4f7f\u7528getComputedStyle\u548ccurrentStyle \u83b7\u53d6\u5143\u7d20\u9ad8\u5ea6demo<\/a><\/p>\n<p>\u7ed3\u679cFireFox\u4e0b\u663e\u793a<code>24px<\/code>(\u7ecf\u8fc7\u8ba1\u7b97\u4e86), \u800cIE\u6d4f\u89c8\u5668\u4e0b\u5219\u662fCSS\u4e2d\u7684<code>2em<\/code>\u5c5e\u6027\u503c\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"Firefox\u4e0b\u663e\u793a\u7684\u8ba1\u7b97\u540e\u768424px\u503c \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_220826.png\" title=\"Firefox\u4e0b\u663e\u793a\u7684\u8ba1\u7b97\u540e\u768424px\u503c\" class=\"alignnone\" width=\"315\" height=\"211\" \/> <img loading=\"lazy\" decoding=\"async\" alt=\"IE9\u4e0b\u663e\u793a\u7684CSS\u4e2d\u76842em\u503c \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_220905.png\" title=\"IE9\u4e0b\u663e\u793a\u7684CSS\u4e2d\u76842em\u503c \" class=\"alignnone\" width=\"307\" height=\"226\" \/><\/p>\n<p><code>getComputedStyle<\/code>\u65b9\u6cd5\u4e0e<code>currentStyle<\/code>\u5c5e\u6027\u5176\u4ed6\u5177\u4f53\u5dee\u5f02\u8fd8\u6709\u5f88\u591a\uff0c\u6211\u4ee5\u4e00\u4e2a\u666e\u901a\u6309\u94ae\u505a\u5143\u7d20\uff0c\u904d\u5386\u4e86\u5176\u4e2d\u9760\u8c31\u7684\u5c5e\u6027\u540d\u548c\u5c5e\u6027\u503c\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201205\/currentstyle-getcomputedstyle-test.html\">getComputedStyle\u548ccurrentStyle\u5c5e\u6027\u5c55\u793ademo<\/a><\/p>\n<p>\u4ed4\u7ec6\u5bf9\u6bd4\u67e5\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e0d\u5c11\u5dee\u5f02\uff0c\u4f8b\u5982\u6d6e\u52a8\u5c5e\u6027\uff0cFireFox\u6d4f\u89c8\u5668\u4e0b\u662f\u8fd9\u4e2a(<code>cssFloat<\/code>)\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"FireFox\u4e0b\u7684\u6d6e\u52a8\u5c5e\u6027\u540d \" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_221607.png\" title=\"FireFox\u4e0b\u7684\u6d6e\u52a8\u5c5e\u6027\u540d\" class=\"alignnone\" width=\"227\" height=\"107\" \/><\/p>\n<p>IE7\u6d4f\u89c8\u5668\u4e0b\u5219\u662f<code>styleFloat<\/code> \uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"IE7\u6d4f\u89c8\u5668\u4e0b\u7684styleFloat\u5c5e\u6027 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_221737.png\" title=\"IE7\u6d4f\u89c8\u5668\u4e0b\u7684styleFloat\u5c5e\u6027\" class=\"alignnone\" width=\"263\" height=\"136\" \/><\/p>\n<p>\u800cIE9\u6d4f\u89c8\u5668\u4e0b\u5219\u662f<code>cssFloat<\/code>\u548c<code>styleFloat<\/code>\u90fd\u6709\u3002<\/p>\n<p>\u7b49\u5176\u4ed6N\u591a\u5dee\u5f02\u3002<\/p>\n<h3>\u4e03\u3001getPropertyValue\u65b9\u6cd5<\/h3>\n<p><code>getPropertyValue<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6CSS\u6837\u5f0f\u7533\u660e\u5bf9\u8c61\u4e0a\u7684\u5c5e\u6027\u503c\uff08\u76f4\u63a5\u5c5e\u6027\u540d\u79f0\uff09\uff0c\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>window.getComputedStyle(element, null).getPropertyValue(\"float\");<\/pre>\n<\/div>\n<p>\u5982\u679c\u6211\u4eec\u4e0d\u4f7f\u7528<code>getPropertyValue<\/code>\u65b9\u6cd5\uff0c\u76f4\u63a5\u4f7f\u7528\u952e\u503c\u8bbf\u95ee\uff0c\u5176\u5b9e\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u4f46\u662f\uff0c\u6bd4\u5982\u8fd9\u91cc\u7684\u7684<code>float<\/code>\uff0c\u5982\u679c\u4f7f\u7528\u952e\u503c\u8bbf\u95ee\uff0c\u5219\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528<code>getComputedStyle(element, null).float<\/code>\uff0c\u800c\u5e94\u8be5\u662f<code>cssFloat<\/code>\u4e0e<code>styleFloat<\/code>\uff0c\u81ea\u7136\u9700\u8981\u6d4f\u89c8\u5668\u5224\u65ad\u4e86\uff0c\u6bd4\u8f83\u6298\u817e\uff01<\/p>\n<p>\u4f7f\u7528<code>getPropertyValue<\/code>\u65b9\u6cd5\u4e0d\u5fc5\u53ef\u4ee5\u9a7c\u5cf0\u4e66\u5199\u5f62\u5f0f\uff08\u4e0d\u652f\u6301\u9a7c\u5cf0\u5199\u6cd5\uff09\uff0c\u4f8b\u5982\uff1a<code>style.getPropertyValue(\"border-top-left-radius\")<\/code>;<\/p>\n<p><strong>\u66f4\u65b0\u4e8e2018-05-30<\/strong><\/p>\n<p><code>getPropertyValue<\/code>\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u83b7\u53d6CSS\u539f\u751f\u53d8\u91cf\u503c\uff0c\u5982\u4e0b\u793a\u610f\uff1a<\/p>\n<pre>const sidebarElement = document.querySelector('.sidebar');\n\n<span style=\"color:green;\">\/\/ cssStyles\u5305\u542bsidebarElement\u5143\u7d20\u7684\u6837\u5f0f<\/span>\nconst cssStyles = getComputedStyle(sidebarElement);\n\n<span style=\"color:green;\">\/\/ \u83b7\u53d6 --left-pos CSS \u53d8\u91cf\u503c<\/span>\nconst cssVal = String(cssStyles.getPropertyValue('--left-pos')).trim(); \n\n<span style=\"color:green;\">\/\/ \u8f93\u51facssVal\n\/\/ \u8f93\u51fa\u53d8\u91cf\u503c\u662f\uff1a100px <\/span>\nconsole.log(cssVal);<\/pre>\n<p>\u8bbe\u7f6eCSS\u53d8\u91cf\u53ef\u4ee5\u4f7f\u7528<code>setProperty()<\/code>\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>sidebarElement.style.setProperty('--left-pos', '200px');<\/pre>\n<p><strong>\u517c\u5bb9\u6027<\/strong><br \/>\n<code>getPropertyValue<\/code>\u65b9\u6cd5IE9+\u4ee5\u53ca\u5176\u4ed6\u73b0\u4ee3\u6d4f\u89c8\u5668\u90fd\u652f\u6301\uff0c\u89c1\u4e0b\u8868\uff1a<\/p>\n<table class=\"params_table\">\n<tbody>\n<tr>\n<th>&nbsp;<\/th>\n<th>Chrome<\/th>\n<th>Firefox (Gecko)<\/th>\n<th>Internet Explorer<\/th>\n<th>Opera<\/th>\n<th>Safari<\/th>\n<\/tr>\n<tr>\n<td>\u57fa\u672c\u652f\u6301<\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td>9<\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<td><span title=\"\u5347\u7ea7\u5230\u6700\u8fd1\u7684\u7248\u672c\"><img decoding=\"async\" src=\"http:\/\/www.zhangxinxu.com\/study\/image\/ok.gif\" alt=\"\u652f\u6301\" \/><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>OK\uff0c\u4e00\u6d89\u53ca\u5230\u517c\u5bb9\u6027\u95ee\u9898(IE6-8\u80bf\u4e48\u529e)\uff0c\u611f\u89c9\u5934\u5f00\u59cb\u5fae\u5fae\u4f5c\u75db\u4e86~~\uff0c\u4e0d\u6025\uff0cIE\u81ea\u7531\u4e00\u5957\u81ea\u5df1\u7684\u5957\u8def\uff0c\u5c31\u662f<code>getAttribute<\/code>\u65b9\u6cd5\u3002<\/p>\n<h3>\u516b\u3001getPropertyValue\u548cgetAttribute<\/h3>\n<p>\u5728\u8001\u7684IE\u6d4f\u89c8\u5668\uff08\u5305\u62ec\u6700\u65b0\u7684\uff09\uff0c<code>getAttribute<\/code>\u65b9\u6cd5\u63d0\u4f9b\u4e86\u4e0e<code>getPropertyValue<\/code>\u65b9\u6cd5\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8bbf\u95eeCSS\u6837\u5f0f\u5bf9\u8c61\u7684\u5c5e\u6027\u3002\u7528\u6cd5\u4e0e<code>getPropertyValue<\/code>\u7c7b\u4f3c\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>style.getAttribute(\"float\");<\/pre>\n<\/div>\n<p>\u6ce8\u610f\u5230\u6ca1\uff0c\u4f7f\u7528<code>getAttribute<\/code>\u65b9\u6cd5\u4e5f\u4e0d\u9700\u8981<code>cssFloat<\/code>\u4e0e<code>styleFloat<\/code>\u7684\u602a\u5f02\u5199\u6cd5\u4e0e\u517c\u5bb9\u6027\u5904\u7406\u3002\u4e0d\u8fc7\uff0c\u8fd8\u662f\u6709\u4e00\u70b9\u5dee\u5f02\u7684\uff0c\u5c31\u662f\u5c5e\u6027\u540d\u9700\u8981\u9a7c\u5cf0\u5199\u6cd5\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>style.getAttribute(\"backgroundColor\");<\/pre>\n<\/div>\n<p>\u5982\u679c\u4e0d\u8003\u8651IE6\u6d4f\u89c8\u5668\uff0c\u8c8c\u4f3c\u4e5f\u662f\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>style.getAttribute(\"background-color\");<\/pre>\n<\/div>\n<p>\u5b9e\u4f8b\u624d\u662f\u738b\u9053\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201205\/getpropertyvalue-getAttribute-background-color.html\">getPropertyValue\u548cgetAttribute\u83b7\u53d6\u80cc\u666f\u8272demo<\/a><\/p>\n<p>\u7ed3\u679cFireFox\u4e0b\u4e00\u5982\u65e2\u5f80\u7684rgb\u989c\u8272\u8fd4\u56de(Chrome\u4e5f\u662f\u8fd4\u56dergb\u989c\u8272)\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"FireFox\u6d4f\u89c8\u5668\u4e0b\u4e00\u5982\u65e2\u5f80\u7684RGB\u989c\u8272\u8fd4\u56de \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_230119.png\" title=\"FireFox\u6d4f\u89c8\u5668\u4e0b\u4e00\u5982\u65e2\u5f80\u7684RGB\u989c\u8272\u8fd4\u56de\" class=\"alignnone\" width=\"355\" height=\"211\" \/><\/p>\n<p>\u5bf9\u4e8eIE9\u6d4f\u89c8\u5668\uff0c\u867d\u7136\u5e94\u7528\u7684\u662f<code>currentStyle<\/code>, \u4f46\u662f\u4ece\u7ed3\u679c\u4e0a\u6765\u8bb2\uff0c<code>currentStyle<\/code>\u8fd4\u56de\u7684\u5bf9\u8c61\u662f\u5b8c\u5168\u652f\u6301<code>getPropertyValue<\/code>\u65b9\u6cd5\u7684\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201205\/2012-05-08_230242.png\" title=\"IE9\u4e0b\u622a\u56fe\" class=\"alignnone\" width=\"421\" height=\"253\" \/><\/p>\n<h3>\u4e5d\u3001getPropertyValue\u548cgetPropertyCSSValue<\/h3>\n<p>\u4ece\u957f\u76f8\u4e0a\u770b<code>getPropertyCSSValue<\/code>\u4e0e<code>getPropertyValue<\/code>\u662f\u8fd1\u4eb2\uff0c\u4f46\u5b9e\u9645\u4e0a\uff0c<code>getPropertyCSSValue<\/code>\u8981\u987d\u52a3\u7684\u591a\u3002<\/p>\n<p><code>getPropertyCSSValue<\/code>\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2aCSS\u6700\u521d\u503c(CSSPrimitiveValue)\u5bf9\u8c61(width, height, left, &#8230;)\u6216CSS\u503c\u5217\u8868(CSSValueList)\u5bf9\u8c61(backgroundColor, fontSize, &#8230;)\uff0c\u8fd9\u53d6\u51b3\u4e8e<code>style<\/code>\u5c5e\u6027\u503c\u7684\u7c7b\u578b\u3002\u5728\u67d0\u4e9b\u7279\u522b\u7684style\u5c5e\u6027\u4e0b\uff0c\u5176\u8fd4\u56de\u7684\u662f\u81ea\u5b9a\u4e49\u5bf9\u8c61\u3002\u8be5\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7ee7\u627f\u4e8eCSSValue\u5bf9\u8c61\uff08\u5c31\u662f\u4e0a\u9762\u6240\u8bf4\u7684<code>getComputedStyle<\/code>\u4ee5\u53ca<code>currentStyle<\/code>\u8fd4\u56de\u5bf9\u8c61\uff09\u3002<\/p>\n<p><code>getPropertyCSSValue<\/code>\u65b9\u6cd5\u517c\u5bb9\u6027\u4e0d\u597d\uff0cIE9\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0cOpera\u6d4f\u89c8\u5668\u4e5f\u4e0d\u652f\u6301\uff08\u5b9e\u9645\u652f\u6301\uff0c\u53ea\u662f\u8001\u662f\u629b\u51fa\u5f02\u5e38\uff09\u3002\u800c\u4e14\uff0c\u867d\u7136FireFox\u4e2d\uff0c<code>style<\/code>\u5bf9\u8c61\u652f\u6301<code>getPropertyCSSValue<\/code>\u65b9\u6cd5\uff0c\u4f46\u603b\u662f\u8fd4\u56de<code>null<\/code>. \u56e0\u6b64\uff0c\u76ee\u524d\u6765\u8bb2\uff0c<code>getPropertyCSSValue<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5148\u4e0d\u95fb\u4e0d\u95ee\u3002<\/p>\n<h3>\u5341\u3001\u8865\u5145~\u7ed3\u8bed<\/h3>\n<p>\u6709\u4e86jQuery\u7b49\u4f18\u79c0\u5e93\uff0c\u6211\u4eec\u6709\u719f\u6089\u5e95\u5c42\u7684<code>getComputedStyle<\/code>\u65b9\u6cd5\u7684\u5fc5\u8981\u5417\uff1f<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u672c\u6587\u4e00\u76f4\u6ca1\u6709\u6df1\u5165\u5c55\u5f00<code>getComputedStyle<\/code>\u65b9\u6cd5\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\uff0c\u7c7b\u4f3c<code>css()<\/code>\u65b9\u6cd5\u6ca1\u6709\u7684\u529f\u80fd\u2014\u2014\u83b7\u53d6\u4f2a\u7c7b\u5143\u7d20\u6837\u5f0f\u3002\u4f46\u4ece\u8fd9\u4e00\u70b9\u4e0a\u5c06\uff0c\u719f\u6089<code>getComputedStyle<\/code>\u65b9\u6cd5\u6709\u5fc5\u8981\u3002<\/p>\n<p>\u4e0b\u4e00\u7bc7\u6587\u7ae0\uff0c\u6211\u5c31\u5c06\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0<code>getComputedStyle<\/code>\u65b9\u6cd5\u5728\u4f2a\u7c7b\u5143\u7d20\u4e0a\u7684\u7279\u5f02\u529f\u80fd\uff0c\u5b9e\u73b0CSS3 media queries\u4e0b\u4e00\u4e9bJS\u4ea4\u4e92\uff0c\u53ca\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n<p>well, \u5f00\u7bc7\u5df2\u7ecf\u5570\u54e9\u5427\u55e6\u4e0d\u5c11\u5185\u5bb9\u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u518d\u8bb2\u5e9f\u8bdd\u4e86\u3002\u884c\u6587\u5306\u5fd9\uff0c\u6587\u4e2d\u96be\u514d\u6709\u8868\u8ff0\u4e0d\u51c6\u786e\u4e4b\u5904\uff0c\u6b22\u8fce\u6307\u6b63\u3002\u6b22\u8fce\u8865\u5145\uff0c\u611f\u8c22\u9605\u8bfb\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u81ea<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<\/a>[<a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a>]<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=2378<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u90fd\u7528\u8fc7jQuery\u7684CSS()\u65b9\u6cd5\uff0c\u5176\u5e95\u5c42\u8fd0\u4f5c\u5c31\u5e94\u7528\u4e86getComputedStyle\u4ee5\u53cagetPropertyValue\u65b9\u6cd5\u3002<br \/>\n\u5bf9\u4e8e\u90a3\u4e9b\u53ea\u60f3\u6df7\u53e3\u996d\u5403\u7684\u4eba\u6765\u8bb2\uff0c\u6653\u5f97CSS()\u5982\u4f55\u4f7f\u7528\u5c31\u8db3\u591f\u4e86\u3002\u5bf9\u4e8e\u5e0c\u671b\u5728JS\u9053\u8def\u4e0a\u8d8a\u8d70\u8d8a\u8fdc\u7684\u6765\u4eba\u8bf4\uff0c\u7b80\u5355\u4e86\u89e3\u4e00\u4e9bJS\u5e93\u5e95\u5c42\u5b9e\u73b0\u5bf9\u81ea\u5df1\u7684\u5b66\u4e60\u5f88\u6709\u5e2e\u52a9\u3002\u53ef\u80fd\u8c08\u4e0d\u4e0a\u4fe1\u624b\u62c8\u6765\u7684\u4f7f\u7528\uff0c\u81f3\u5c11\u5bf9\u521b\u9020\u4e00\u4e9b\u521b\u610f\u65b0\u9896\u7684\u65b0\u6280\u672f\u62d3\u5bbd\u4e86\u601d\u8def\u3002<br \/>\njQuery\u4e3a\u4f55\u53d7\u6b22\u8fce\uff0c\u5176\u4e2d\u539f\u56e0\u4e4b\u4e00\u5c31\u662f\u65b9\u6cd5\u540d\u79f0\u6bd4\u2026\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[386,717,716,714,715,496,575,140],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/2378"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2378"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/2378\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}