【发布时间】:2019-07-23 01:32:41
【问题描述】:
我正在编写一些代码来查找以字母“a”开头的段落中的单词。我想知道是否有一个快捷方式可以放在变量中。我确实知道 startsWith() 函数,但这不适用于我想要做的事情。这是我到目前为止所拥有的。我正在尝试使用 match 方法和 .innerText 来阅读段落。
function processText() {
var totalNumberOfWords = document.getElementById('p')
var wordsBegginingWithA = 0;
var wordsEndingWithW = 0;
var wordsFourLettersLong = 0;
var hyphenatedWords = 0;
}
<p><button onClick="processText();">Process</button></p>
<p id="data"></p>
<p>The thousand injuries of Fortunato I had borne as I best could; but when he ventured upon insult, I vowed revenge. You, who so well know the nature of my soul, will not suppose, however, that I gave utterance to a threat.
<span style='font-style:italic;'>At
length</span> I would be avenged; this was a point definitely settled--but the very definitiveness with which it was resolved precluded the idea of risk. I must not only punish, but punish with impunity. A wrong is unredressed when retribution
overtakes its redresser. It is equally unredressed when the avenger fails to make himself felt as such to him who has done the wrong.</p>
【问题讨论】:
-
我们需要一些代码来帮助您...
-
改变了它。如果您需要更多代码,请 Lmk
-
能否提供相关段落
-
很长,大约300行。我可以给出我已链接到该功能的段落和按钮之一吗?
-
只给出包含所有需要内容的段落的一小部分。
标签: javascript html