我有以下代码:
var currentServerlist = [];
var newServerIp = document.getElementById('add_server').value;
if( CurrentServerIP != newServerIp )
{
$('#failoverServers td.row_selector').each(function() {
var row = $(this).closest('tr');
var serverIp = row.find('td[rel=ip]').text();
currentServerlist.push(serverIp);
});
if(currentServerlist.lastIndexOf(newServerIp) != -1)
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
但是我发现lastIndexOf在InternetExplorer中不起作用(在Chrome中也是如此).
我怎样才能解决这个问题?
根据ES5兼容性表,Array.prototype.lastIndexOf除IE8及以下版本外,所有浏览器均支持.
如果您需要支持此类浏览器,您可以使用可用的各种填充剂之一(或更完整的ES5 polyfill解决方案).