我正在研究一个查看页面上的表值列表的函数,如果列标题包含任何部分output,它将相应地转换该值.
function createLink(field, val) {
var output = {
'ntid': 'https://internal/profile/' + val,
'email': 'mailTo:' + val
};
var i, key, keys = Object.keys(output);
for ( i = 0; i < keys.length; ++i ) {
key = keys[i];
if ((field.toLowerCase()).includes(key)) {
return '<a href="'+output[key]+'" target="_blank">'+val+'</a>';
}
}
return val;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是IE .includes()在行上引发错误,指出"对象不支持属性或方法'包含'".
我有点麻烦让它按原样运行,但没有意识到includes()必须是并非所有浏览器都支持的东西.
还有什么我可以用来代替这个,以支持跨浏览器支持吗?
更换:
if(field.toLowerCase().includes(key)) {
Run Code Online (Sandbox Code Playgroud)
至:
if(field.toLowerCase().indexOf(key) > -1) {
Run Code Online (Sandbox Code Playgroud)