简体   繁体   English

jQuery脚本在IE 7-8中不起作用

[英]Jquery script doesn't work in IE 7-8

In IE 7-8 don't work script. 在IE 7-8中,请勿使用脚本。 Error on 3th string. 第3个字符串错误。 I cant't find the error. 我找不到错误。 From russian: "object don`t support this property or method". 从俄语起:“对象不支持此属性或方法”。

Include in html: 包含在html中:

<script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.red-first.js"></script>

jquery.red-first.js: jquery.red-first.js:

(function($) {
    $.fn.redFirst = function() {
        var city = $(this).text().trim();
        var newCity;
        if (city == 'г. Москва') { city = 'Москва'; }
        if (city == 'г. Санкт-Петербург') { city = 'Санкт-Петербург'; }
        var cityWords = city.split(' ');
        if (cityWords.length == 1) {
            newCity = '<span class="red">' + city[0] + '</span>';
            newCity = newCity + city.slice(1);;
        } else {
            newCity = '<span class="red">' + cityWords[0] + '</span>';
            delete cityWords[0];
            newCity = newCity + cityWords.join(' ');
        }
        $(this).html(newCity);
        return this;
    };
})(jQuery);

$(document).ready(function(){
    $('#city').redFirst();
    $('#choose_reg_city').redFirst();
    $('#authorization #region').redFirst();
});

string.trim() isn't a function that comes in IE. string.trim()不是IE中附带的函数。 Other browsers define it but IE doesn't. 其他浏览器定义它,但IE未定义。 Since you are using jQuery already use this instead: 由于您使用的是jQuery,因此请改用以下代码:

var city = $.trim($(this).text());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM