为 chrome 制作简单的扩展。将“querySelector”更改为“querySelectorAll”时,第二个功能不起作用。
var ele2 = document.querySelectorAll(".view-count ");
window.onload = function(){
func2();
}
function func2(){
ele2.innerHTML = ele2.innerHTML.trim();
ele2.innerHTML = ele2.innerHTML.slice(0, -14);
ele2.textContent = "$" + ele2.innerHTML.replace(/ /g,' ');
}
解决方案 :
for (x=0;x<ele2.length;x++){ele2[x].innerHTML = ele2[x].innerHTML.trim();}
for (x=0;x<ele2.length;x++){ele2[x].innerHTML = ele2[x].innerHTML.slice(0, -14);}
for (x=0;x<ele2.length;x++){ele2[x].textContent = "$" + ele2[x].innerHTML.replace(/ /g,' ');}