jQuery templates, how can I use inputs?

这一生的挚爱 提交于 2019-12-25 06:35:12

问题


After this conversation I started wondering if it's possible to use that and apply to textboxes. I want something like that:

<script type="jquery/x-jquery-tmpl" id="contactTemplate" >
<div>
    <input type="text" value= {{ = name }}  />
    <input type="text" value= {{ = phone }}  />
<div>
</script>

<script type="text/javascript">
   var contacts = { name: 'Scott Guthrie', phone: '31415' };

   $(document).ready(function() 
  {
      $('#contactTemplate').tmpl(contacts).appendTo('#contactContainer');
  });
</script>

回答1:


Sure thing:

<script type="jquery/x-jquery-tmpl" id="contactTemplate" >
    <div>
        <input type="text" value="${name}"  />
        <input type="text" value="${phone}"  />
        <div>
</script>

Here's an example: http://jsfiddle.net/Ca35T/



来源:https://stackoverflow.com/questions/5747426/jquery-templates-how-can-i-use-inputs

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