亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何向 p 標簽添加一些類?

如何向 p 標簽添加一些類?

慕尼黑5688855 2022-01-07 16:33:38
我想在 p 標簽中添加一些類。我該怎么做?const separatorsList = [    { start: '<!-- Excerpt Start -->', end: '<!-- Excerpt End -->' },    { start: '<p>', end: '</p>' }  ];
查看完整描述

2 回答

?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

您可以映射您的數組并將您的開始標簽替換為包含您想要的類的標簽。


const separatorsList = [{

    start: '<!-- Excerpt Start -->',

    end: '<!-- Excerpt End -->'

  },

  {

    start: '<p>',

    end: '</p>'

  }

];


const res = separatorsList.map(({

  start,

  end

}) => ({

  start: start.replace("<p>", "<p class='yourClass'>"),

  end

}))


console.log(res)


查看完整回答
反對 回復 2022-01-07
?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

這是完整的代碼,并提供一些背景知識。這是從eleventy.js。我的目標是為博客中的摘錄設置樣式。現在,我必須去每個 Markdown 文件并設置它的樣式。我想知道有沒有更好的方法,比如在 p 標簽中添加一個全局變量。


注意:對不起,我對javascript的了解很少。


function extractExcerpt(article) {

  if (!article.hasOwnProperty('templateContent')) {

    console.warn('Failed to extract excerpt: Document has no property "templateContent".');

    return null;

  }


  let excerpt = null;

  const content = article.templateContent;


  // The start and end separators to try and match to extract the excerpt

  const separatorsList = [

    { start: '<!-- Excerpt Start -->', end: '<!-- Excerpt End -->' },

    { start: '<p class="f5 pt0 mt1 pl3 black-70">', end: '</p>' }

  ];


  separatorsList.some(separators => {

    const startPosition = content.indexOf(separators.start);

    const endPosition = content.lastIndexOf(separators.end);


    if (startPosition !== -1 && endPosition !== -1) {

      excerpt = content.substring(startPosition + separators.start.length, endPosition).trim();

      return true; // Exit out of array loop on first match

    }

  });


  return excerpt;

}


查看完整回答
反對 回復 2022-01-07
  • 2 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號