如何使用String.prototype.startsWith filter with HTML table
这是我的项目使用json的例子,但我必须在我的项目中使用filter数组。
http://jsfiddle.net/8kkg3/3471/
这是过滤器的代码,我想把它和表一起使用。
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str) {
return this.substring(0, str.length) === str;
}
};
const str ='John';
let result =str.startsWith('j');
console.log(result);
"J" == "j"
以上陈述将被评估为虚假。下面的resultA
和resultB
都将为True。
const str = 'John';
let resultA = str.startsWith('J');
let resultB = str.toLowerCase().startsWith('j');
console.log(resultA);
console.log(resultB);
下面是对fiddle的更新,它根据输入过滤表。
顺便说一句,你的标记有点偏离了——你不应该把标题"用户名"放在表体。您还缺少tbody
和thead
元素。
此外,var
的使用也被认为是不可取的。您应该使用let
和const
(请参阅此处获取指南(。