[英]Replace text using Javascript
我想用保存文本length
來替換網頁中的所有文本,例如:
從:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id dui tincidunt
至:
sample text sample text sample text sample text sample text sample text sampl
我是Java語言的新手,但我聽不懂。 è_é
請幫我。
創建一個函數,該函數使用單詞字符串替換,並重復字符串直到長度,然后簡單地追加到變量,直到達到長度為止:
function replaceTextWithLength(textToReplace, replaceText) {
var length = textToReplace.length;
var text = "";
while (text.length < length) {
text += replaceText;
}
return text.substring(0, length);
}
var words = replaceTextWithLength("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id dui tincidunt", "sample text ");
console.log(words);
演示: http : //jsfiddle.net/zdvz59yb/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.