comments

功能描述

快速使用

  1. let msgBoxList = JSON.parse(window.localStorage.getItem('msgBoxList')) || [];
  2. innerHTMl(msgBoxList)
  3. //点击发表按扭,发表内容
  4. $("span.submit").click(function () {
  5. let txt = $(".message").html(); //获取输入框内容
  6. if (!txt) {
  7. $('.message').focus(); //自动获取焦点
  8. return;
  9. }
  10. msg: txt
  11. }
  12. window.localStorage.setItem('msgBoxList', JSON.stringify(msgBoxList)) //将数据保存到缓存
  13. innerHTMl([obj]) //渲染当前输入框内容
  14. $('.message').html('') // 清空输入框
  15. });
  16. //渲染html
  17. function innerHTMl(List) {
  18. List = List || []
  19. List.forEach(item => {
  20. let str =
  21. <div class="headUrl">
  22. <div>
  23. <span class="title">木林森里没有木</span>
  24. <span class="time">2018-01-01</span>
  25. </div>
  26. <a class="del">删除</a>
  27. </div>
  28. <div class='msgTxt'>
  29. ${item.msg}
  30. </div>
  31. </div>`
  32. $(".msgCon").prepend(str);
  33. })

特别说明