Tập lệnh này kiểm tra tất cả các phần tử bằng một lớp .fixMinMaxwidth và quan sát cửa sổ. Nó chỉ được áp dụng cho các trình duyệt không có hỗ trợ độ rộng tối thiểu / tối đa gốc, chẳng hạn như ie6 trở xuống. Thay đổi kích thước cửa sổ cũng không phải là một vấn đề.
//anonymous function to check all elements with class .fixMinMaxwidth var fixMinMaxwidth=function() ( //only apply this fix to browsers without native support if (typeof document.body.style.maxHeight !== "undefined" && typeof document.body.style.minHeight !== "undefined") return false; //loop through all elements $('.fixMinMaxwidth').each(function() ( //get max and minwidth via jquery var maxWidth = parseInt($(this).css("max-width")); var minWidth = parseInt($(this).css("min-width")); //if min-/maxwidth is set, apply the script if (maxWidth>0 && $(this).width()>maxWidth) ( $(this).width(maxWidth); ) else if (minWidth>0 && $(this).width()