IE7 中的 Swipebox 插件错误(对象不支持 属性 或方法 'trim' )

Swipebox plugin errors in IE7 (Object doesn't support property or method 'trim' )

Swipebox jquery 插件在 IE7 中单击任何附加图像时会出错(以在弹出模式框中显示)。错误具体指向jquery.swipebox.js in Line:815,说:

Object doesn't support property or method 'trim'

行:815代码如下:

loadMedia : function ( src, callback ) {
    // Inline content
    if ( src.trim().indexOf('#') === 0 ) {       // <=== Line:815
        callback.call(...)

经过一番搜索,我发现了以下对我来说非常有效的解决方案。

.trim() in JavaScript not working in IE

我在 if 条件之前添加了以下代码:

if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, ''); 
    }
}