如何使用jquery美化html标记

如何使用jquery美化html标记,jquery,html,css,Jquery,Html,Css,我需要对齐来自后端php的html标记。如何整齐地对齐html标记并向用户显示它们 <!DOCTYPE html> <html lang="en"> <head> <style type="text/css"> .attach_btn{font-family: Helvetica,Arial,sans-serif; font-size: 16px; font-weight: 700; color: #fefefe; t

我需要对齐来自后端php的html标记。如何整齐地对齐html标记并向用户显示它们

<!DOCTYPE html>
<html lang="en">
   <head>
      <style type="text/css">
      .attach_btn{font-family: Helvetica,Arial,sans-serif; font-size: 16px; font-weight: 700; color: #fefefe; text-decoration: none; display: inline-block; padding: 8px 16px; border-radius: 3px; background: #243f89; border: none; border-color: #243f89;}p{margin:10px 0; padding:0;}table{border-collapse:collapse;}h1,h2,h3,h4,h5,h6{display:block; margin:0; padding:0;}img,a img{border:0; height:auto; outline:none; text-decoration:none;}body,#bodyTable,#bodyCell{height:100%; margin:0; padding:0; width:100%;}.mcnPreviewText{display:none !important;}#outlook a{padding:0;}img{-ms-interpolation-mode:bicubic;}table{mso-table-lspace:0pt; mso-table-rspace:0pt;}
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <title>Purple Admin</title>
      <link rel="stylesheet" href="vendors/iconfonts/mdi/css/materialdesignicons.min.css">
      <link rel="stylesheet" href="vendors/css/vendor.bundle.base.css">
      <link rel="stylesheet" href="css/style.css">
      <link rel="shortcut icon" href="images/favicon.png"/>
   </head>
   <body>
      <div class="container-scroller">
   </body>
</html>

我以前有这样的要求。谢天谢地,我找到了一个库,它做了适当的缩进以提高可读性。希望这对您也有帮助:

<script src='http://lovasoa.github.io/tidy-html5/tidy.js'></script>
<script>
  options = {
  "indent":"auto",
  "indent-spaces":2,
  "wrap":80,
  "markup":true,
  "output-xml":false,
  "numeric-entities":true,
  "quote-marks":true,
  "quote-nbsp":false,
  "show-body-only":true,
  "quote-ampersand":false,
  "break-before-br":true,
  "uppercase-tags":false,
  "uppercase-attributes":false,
  "drop-font-tags":true,
  "tidy-mark":false
}

var html = document.querySelector("body").outerHTML;
var result = tidy_html5(html, options);
console.log(result);
</script>

来源:

我以前有这样的要求。谢天谢地,我找到了一个库,它做了适当的缩进以提高可读性。希望这对您也有帮助:

<script src='http://lovasoa.github.io/tidy-html5/tidy.js'></script>
<script>
  options = {
  "indent":"auto",
  "indent-spaces":2,
  "wrap":80,
  "markup":true,
  "output-xml":false,
  "numeric-entities":true,
  "quote-marks":true,
  "quote-nbsp":false,
  "show-body-only":true,
  "quote-ampersand":false,
  "break-before-br":true,
  "uppercase-tags":false,
  "uppercase-attributes":false,
  "drop-font-tags":true,
  "tidy-mark":false
}

var html = document.querySelector("body").outerHTML;
var result = tidy_html5(html, options);
console.log(result);
</script>

来源:

您可以使用javascript执行以下操作:

var htmlstr='.attach_btn{font系列:Helvetica,Arial,无衬线;字体大小:16px;字体重量:700;颜色:fefefefe;文本装饰:无;显示:内联块;填充:8px 16px;边框半径:3px;背景:243f89;边框:无;边框颜色:243f89;}p{margin:10px 0;填充:0;}表格{边框折叠:折叠;}h1、h2、h3、h4、h5、h6{display:block;margin:0;padding:0;}img,a img{border:0;height:auto;outline:none;text defination:none;}body,bodyTable,bodyCell{height:100%;margin:0;padding:0;width:100%;}.mcnPreviewText{display:none!重要;}outlook a{padding:0;}img{-ms插值模式:双三次曲线;}table{mso table lspace:0pt;mso table rspace:0pt;}Purple Admin;
htmlstr=htmlstr.split/\>[]?\您可以使用javascript执行以下操作:

var htmlstr='.attach_btn{font系列:Helvetica,Arial,无衬线;字体大小:16px;字体重量:700;颜色:fefefefe;文本装饰:无;显示:内联块;填充:8px 16px;边框半径:3px;背景:243f89;边框:无;边框颜色:243f89;}p{margin:10px 0;填充:0;}表格{边框折叠:折叠;}h1、h2、h3、h4、h5、h6{display:block;margin:0;padding:0;}img,a img{border:0;height:auto;outline:none;text defination:none;}body,bodyTable,bodyCell{height:100%;margin:0;padding:0;width:100%;}.mcnPreviewText{display:none!重要;}outlook a{padding:0;}img{-ms插值模式:双三次曲线;}table{mso table lspace:0pt;mso table rspace:0pt;}Purple Admin;
htmlstr=htmlstr.split/\>[]?\n你可以在线美化你的html,有很多html美化工具,例如用户不会看到或关心你的html标记。最好的方法是在发送到客户端之前在后端格式化。然后如何使用html标记所在的php在后端格式化html标记database@DavidJapan如果您使用电子邮件发送,后端的格式设置也不起作用字符串,对吗?你可以在线美化你的html,有很多html美化工具,比如用户不会看到或关心你的html标记。最好的方法是在发送到客户端之前在后端格式化html标记…然后如何使用html标记所在的php在后端格式化html标记database@DavidJapan如果您发送邮件,后端的格式化也不起作用用字符串美化代码,对吗?这很好,但不适用于和tagsI刚才在回答时给了你提示,如何使用正则表达式格式化代码,你必须使用更多的正则表达式来美化代码。或者你也可以美化代码,这比在JavaScription中添加大量正则表达式要好。这很好,但不适用于和tagsIst在回答中提示您如何使用正则表达式格式化代码,您必须使用更多的正则表达式来美化代码。或者您也可以在处美化代码,这比在JavaScript中添加大量正则表达式要好