prettify实现html页面黑色高亮代码

浏览716

头部引入prettify样式和js:

    
    


给body加onload="prettyPrint()"方法



底部script代码:

    


效果:

var currentTime = Math.floor(parseInt(audio.currentTime)/60)+":"+(parseInt(audio.currentTime)%60/100).toFixed(2).slice(-2); 
    console.log(Math.floor(parseInt(currentTime)/60)+":"+(parseInt(currentTime)%60/100).toFixed(2).slice(-2));
    $("#current").html(currentTime);
}

pre标签代码换行:

pre { 
white-space: pre-wrap; /*css-3*/ 
white-space: -moz-pre-wrap; /*Mozilla,since1999*/ 
white-space: -pre-wrap; /*Opera4-6*/ 
white-space: -o-pre-wrap; /*Opera7*/ 
word-wrap: break-word; /*InternetExplorer5.5+*/ 
}


附件:重命名为css和js文件

prettify.css.txt

prettify.js.txt




  • 暂无任何回答