在 JavaScript 中,是否可以从页面上显示的段落中获取特定行?
例如,这里我试图将段落的第 3 行作为字符串获取:
JavaScript:
//this function should return the specified line from the specified paragraph.
function getLine(paragraphId, lineNum){
//for example, getLine("sampleParagraph", 1); should return
// tore but year. An from mean on with when sing pain. Oh to as principles devonshire
}
HTML:
<p id = "sampleParagraph">
Instrument cultivated alteration any favourable expression law far nor. Both new like tore but year. An from mean on with when sing pain. Oh to as principles devonshire companions unsatiable an delightful. The ourselves suffering the sincerity. Inhabit her manners adapted age certain. Debating offended at branched striking be subjects.
</p>
这是在 jsfiddle 上(显示段落的显示方式):http: //jsfiddle.net/RrXWW/