기본 제공되는 솔루션이 있다고 생각하지 않지만 여기서는 유용한 기능을 제공합니다. 그것은메서드를 사용하므로 IE8 이하에서는 작동하지 않는다고 생각합니다. 원하는 경우 선호하는 DOM 쿼리 라이브러리를 사용하십시오.
/**
* Returns the number of lines in a SyntaxHighlighter code block.
*
* @param {Element} node The top-level DOM element containing the code block.
* @return {Number} The number of code lines, or 0 if not found.
*/
function getLineCount(node) {
var codeNode;
var containerNode;
if (node && typeof node.getElementsByClassName === 'function') {
codeNode = node.getElementsByClassName('code');
if (codeNode.length) {
containerNode = codeNode[0].getElementsByClassName('container');
if (containerNode.length) {
return containerNode[0].children.length;
}
}
}
return 0;
}
jQuery 버전, 분명히 사실입니다.
function getLineCount(node) {
return $(node).find('.code .container').children().length;
}