在 IE 7-8 中,脚本不起作用。第三串错误。我找不到错误。 来自俄语:“对象不支持此属性或方法”。
包含在 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:
(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()
不是 IE 中的函数。其他浏览器定义了它,但 IE 没有。由于您正在使用 jQuery,因此已经使用它:
var city = $.trim($(this).text());
关于javascript - Jquery 脚本在 IE 7-8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10607917/