如:IE8不支持indexOf方法;javascript
咱們的解決辦法是:在使用indexOf方法前,執行一下下面的js, 原理就是若是發現數組沒有indexOf方法,會添加上以下方法:java
<script type="text/javascript">數組
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;this
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;prototype
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}ip
</script>io