仅在IE(8)中出现jQuery错误 - "对象不支持..."

sve*_*ija 6 ajax jquery google-maps internet-explorer-8

我在jQuery中有这段代码(AJAX).

$.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&value=5', doSomething);
Run Code Online (Sandbox Code Playgroud)

这是一个功能(在Google地图上显示一个图标并更改输入字段中的某些值).

function doSomething(data) {
    data = data.trim();
    data = data.split(","); 
    var stopName = data[0];
    var stopLat = data[1];
    var stopLon = data[2];

    $("#start").val(stopName);

    if (startMarker == null) {
        startMarker = new google.maps.Marker({
                            position: new google.maps.LatLng(stopLat,stopLon),
                            map: map,
                            zIndex: 2,
                            title: stopName,
                            icon: startImage 
        });
    } else {
        startMarker.setPosition(new google.maps.LatLng(stopLat,stopLon));
    }
}
Run Code Online (Sandbox Code Playgroud)

但它适用于IE以外的所有浏览器,在我的IE 8中.我没有在IE 6/7中测试它.它弹出这个错误......

IE 8中的jquery错误

我查看了jquery.js,这是它打破的功能......

            // resolve with given context and args
            resolveWith: function( context, args ) {
                if ( !cancelled && !fired && !firing ) {
                    firing = 1;
                    try {
                        while( callbacks[ 0 ] ) {
                            callbacks.shift().apply( context, args );
                        }
                    }
                    finally {
                        fired = [ context, args ];
                        firing = 0;
                    }
                }
                return this;
            },
Run Code Online (Sandbox Code Playgroud)

其实

callbacks.shift().apply( context, args );
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?问题出在哪儿?与jquery-1.4.4.js相同

编辑:这是我更大的代码......

    // Set some events on the context menu links
contextMenu.find('a').click( function()
{
    // fade out the menu
    contextMenu.fadeOut(75);

    // The link's href minus the #
    var action = $(this).attr('href').substr(1);

    switch (action) {
        case 'startMenu':
            $.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&radijus=5', doSomethingWithData1);
            break;

        case 'stopMenu':
            $.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&radijus=5', doSomethingWithData2);    
            break;
    }

    return false;
});
Run Code Online (Sandbox Code Playgroud)

当用户点击Google地图上下文菜单中的项目时,请执行" doSomethingWithData1 "和" doSomethingWithData2 ".这也是上下文菜单的一些代码

    // Hover events for effect
contextMenu.find('a').hover( function() {
    $(this).parent().addClass('hover');
}, function() {
    $(this).parent().removeClass('hover');
});
Run Code Online (Sandbox Code Playgroud)

这适用于AJAX

$.ajaxSetup ({  
        cache: false  
    }); 
Run Code Online (Sandbox Code Playgroud)

这就是我包含jQuery脚本的方式.

    <!-- Google Maps -->       
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<!-- Load Javascript / jQuery -->
<script type="text/javascript" src="js/jquery-1.5.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.position.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>

<link rel="stylesheet" href="js/jquery.ptTimeSelect.css" type="text/css" media="all" />

<script type="text/javascript" src="js/jqtransformplugin/jquery.jqtransform.js"></script>
<link rel="stylesheet" href="js/jqtransformplugin/jqtransform.css" type="text/css" media="all" />

<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
Run Code Online (Sandbox Code Playgroud)

sve*_*ija 10

这是JavaScript中的 =/ - .trim()不在IE中工作

解决方案 - 在使用.trim函数之前添加它.

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

  • 你也是我的英雄! (2认同)