自定义小程序组件?

新手求教,这是jquery方法,请问如何将这种方法转换成小程序组件。

`var str = $("#goodIntroduction").text();
var tempt = str;
coverup();

function coverup() {

 if (str.length > 17) {
     $("#goodIntroduction").text(tempt.slice(0, 17) + "...");
 }
 var readmore = "<a onclick='showmore()'  style='color: orange;'>查看更多↓</a>"
 $("#goodIntroduction").append(readmore);

}

function showmore() {

 $("#goodIntroduction").text(str);
 var readmore = "<a onclick='coverup()'  style='color: orange;'>收起↑</a>"
 $("#goodIntroduction").append(readmore);

}`

`<div id="goodIntroduction">

在漫无边际的海水上漂流,偶尔抬头能看见熟悉的日月星辰。因为我不知道下辈子是否还能遇见你,所以我今生才会那么努力把最好的给你。 陪伴,是最长情的告白;而声音,是最温柔的陪伴!

</div>`

阅读 782
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题