假设我有这个html标记:
<div id="wrapper"> <pre class="highlight"> $(function(){ // hide all links except for the first $('ul.child:not(:first)').hide(); $("a.slide:first").css("background-color","#FF9900"); $('ul.parent a.slide').click(function(){ $('ul.parent a.slide').css("background-color","#3399FF"); $('ul.parent a.slide').mouSEOut(function(){ $(this).css("background-color","#3399FF"); }); $('ul.parent a.slide').mouSEOver(function(){ $(this).css("background-color","#66CC66"); }); }); }); </pre> </div>
读取div中存在的每行代码的最简单方法是什么.如何从该div中提取每行代码或以任何我想要的方式循环遍历每一行样式.
编辑:
解决方法
你的意思是这样的:
var lines = $("#wrapper pre").text().split("\n"); $.each(lines,function(n,elem) { console.log(elem); });
因为这是文本(而不是html),所以你应该这样对待它.唯一的方法是读取它然后使用字符串解析例程.