Javascript template parsing in mobile devices

你离开我真会死。 提交于 2019-12-13 05:35:46

问题


I have implemented basic template parser for javascript. it simply replaces variables within template string. i.e {event.date} will be 7/4/2013

I am using script tag to store template string

<script id="date_template" type="text/html"> <span class="date" id="date_{event.id}">  {event.date}  <span> </script> 

but it gives error in mobile devices so I have used div element for this

<div style="display:none" id="date_template"> <span class="date" id="date_{event.id}">  {event.date}  <span> </div> 

but it creates dom element which causes other problems. Is there any other way to do this?


回答1:


Here is another way to do this:

$("<span/>",  
   {
    "class":"date",
    "id":"date_$event.id".replace(/\$event.id/,event.id),
    "html":event.date
   }
 )

References

  • jquery constructor: jquery(html, attributes)


来源:https://stackoverflow.com/questions/19241096/javascript-template-parsing-in-mobile-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!