在 IE 7-8 中不工作脚本。第 3 个字符串出错。我找不到错误。来自俄语:“对象不支持此属性或方法”。
包含在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();
});