jQuery templates, how can I use inputs?

2019-09-03 07:50发布

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条回答
小情绪 Triste *
2楼-- · 2019-09-03 08:18

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/

查看更多
登录 后发表回答