<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://code.jquery.com/jquery-1.11.3.js"></script> <style> *, :after, :before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } </style> </head> <body> <fieldset> <legend>fieldset</legend> </fieldset> <script> $(function () { var elem = $('#fieldset1')[0]; var styles = window.getComputedStyle(elem); var val= jQuery.css(elem, "paddingTop", true, styles); elem.style.height = (200 - val) + "px"; alert(parseInt($('#fieldset1').height(), 10)); }); </script> </body> </html>¡¡¡¡
FirefoxÏÂÎÊÌâÒÀÈ»´æÔÚ£¬ºÜÃ÷ÏÔÊÇÔÚ jQuery.css ÖгöÏÖµÄÎÊÌ⣬¸ú×Ùµ½ jQuery µÄÔ´´úÂ룺
˵°×ÁË£¬Ò²ºÜ¼òµ¥¡£Í¨¹ý styles.getPropertyValue(name) || styles[name] À´»ñȡij¸öCSSÑùʽµÄÖµ¡£
ÏÂÃ棬ÔٴθüÐÂʾÀý£¬È¥³ý jQuery µÄÏà¹Ø´úÂ룺
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://code.jquery.com/jquery-1.11.3.js"></script> <style> *, :after, :before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } </style> </head> <body> <fieldset> <legend>fieldset</legend> </fieldset> <script> $(function () { var elem = $('#fieldset1')[0]; var styles = window.getComputedStyle(elem); var val = parseFloat(styles.getPropertyValue("paddingTop") || styles["paddingTop"]); elem.style.height = (200 - val) + "px"; alert(parseInt($('#fieldset1').height(), 10)); }); </script> </body> </html>¡¡¡¡¡¡¡¡
FirefoxÎÊÌâÒÀÈ»´æÔÚ£¬¶øÕâÀïÃæÎÒÃÇÉèÖà fieldset µÄ¸ß¶È¸ù±¾Ã»Óõ½ jQuery£¬Ö»Êǵ÷ÓÃÁËϵͳµÄ getCompotedStyle ·½·¨µÈ£¡£¡£¡
Öмä²å²¥Ò»¸ö¹ã¸æ£º
#######################################
# 9 ÄêÖ»×öÒ»¼þÊÂ
# ÓÉÈýÉúʯÉÏÇ××Ô´òÔìµÄ FineUI ¿Ø¼þ¿â£¬ÏÖÒÑÖ§³Ö ASP.NET Core 2.0£¬¿çƽ̨ Windows¡¢Mac¡¢Linux ¶¼ÄÜÓã¡
# ÔÚÏßʾÀý£º
########################################
¹ã¸æ½áÊø£¬Çë¼ÌÐø....
ÉÏÃ滹²»ÊÇ×î¼òµ¥£¬ÏÂÃæÎÒÃÇ´ÓÒ³ÃæÖÐÍêÈ«Åųý jQuery £¬3 ÐдúÂë¾ÍÄÜÖØÏÖÎÊÌ⣺
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style> *, :after, :before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } </style> </head> <body> <fieldset> <legend>fieldset</legend> </fieldset> <script> window.onload = function() { var elem = document.getElementById('fieldset1'); window.getComputedStyle(elem)["paddingTop"]; elem.style.height = "200px"; }; </script> </body> </html>¡¡¡¡
¡¡¡¡
ÔÚChromeºÍFirefoxϵÄÏÔʾЧ¹û¶Ô±È£¨ºóÃæÊÇChrome£¬Ç°ÃæÊÇFirefox£©£º
С½á
µÄµÄÈ·È·£¬ÕâÊÇ Firefox Quantum(v57) ÒÔ¼°ºÜ¶àÀÏ°æ±¾µÄBUG£¬ºÍ jQuery ûÓйØϵ£¬jQueryÖ»ÔÚ×öÁ˸Ã×öµÄÊÂÇ飬ÅöÇÉÓöµ½Õâ¸ö Firefox µÄBUG¶øÒÑ¡£
Õâ¸öBUGÔÚFirefoxÏÂÖØÏÖÐèÒªÂú×ãÈçϼ¸¸öÌõ¼þ£º
ÔÚÕâ 3 ¸öÌõ¼þÏ£¬µ÷ÓÃJS´úÂë window.getComputedStyle(elem)["paddingTop"] Ö®ºóÔÙÉèÖà fieldset ±êÇ©µÄ¸ß¶È£¬Ò³ÃæÉϲ»»á¸üУ¡
½â¾ö°ì·¨Çë¿´ÎÒµÄÉÏһƪÎÄÕ£º¡¾Ô´´¡¿×¥¸öFirefoxµÄС±è×Ó£¬Î§¹ÛȺÖÚÓУºChrome¡¢Edge¡¢IE8-11
µãÔÞ
ϲ»¶ÈýʯµÄÎÄÕ£¬Äã¾Í¸ø¸öÍƼöߣ¡
¡¡