$(function() {var cls;$("img").each(function(){cls = $(this).attr("class");if (typeof(cls) == "undefined") {$(this).addClass("img-responsive");} else{if (cls.match("img-responsive") != null) {$(this).addClass("img-responsive");}}});});
原来使用indexof,结果查不到指定字符串,改用match来判断才可以得到结果,在浏览器里报错,说cls.indexof不是一个已经定义的方法。但match没问题。
难道js的indexof方法被废弃了?