The type attribute is text/html when the,<script> fragment defines a code that is called by JS, and the code is not displayed on the page
<script id= "Commenttemplate" type= "text/html" > <li> <div class= "Photo" > <a href= " # "> </a> </div> <p> <a href=" # ">[username]:</a><span class=" Time ">[CreateDate]</span> </p> <div class=" Clear "></div> </li>
The use of the above code fragment
//i g M is used to specify case-sensitive matches, global matches, and multiline matches, respectively. varReg =NewREGEXP ("\\[" ([^\\[\\]]*?) \ \] ", ' IgM '); $("#addFun"). Click (function() { varhtml = document.getElementById ("Commenttemplate"). InnerHTML; varSource = Html.replace (Reg,function(node, key) {return { ' userimg ': ' https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000 &sec=1459913929&di=1934ccc3709e8e2301e73b578270212a&src=http://p7.qhimg.com/t01e6b39b78a7a65ac0.jpg ', ' UserName ': ' ABC ', ' CreateDate ': ' 2011-1-1 '}[key]; }); $("#comment_ul_2"). append (source); }); </script> </body> When you click the button, you can chase the contents of the commenttemplate into the comment_ul_2.
When replacing, you can accept a JSON string and then compare the key in the JS module with the JSON key to assign the value
Make script's Type property equal to text/html