1

私はこのようなものを作成したい:

<table>
    <tr>
         <td><div><font>ID</font></div></td>
         <td><div><font>Name</font></div></td>
    </tr> 
</table>
4

1 に答える 1

1

Javascript に HTML を含めるのは好きではないので、テンプレートで jQuery を使用する方法を次に示します。

私のHTMLで:

<script id="hidden-template" type="text/x-custom-template">
    <tr>
         <td><div><font>ID</font></div></td>
         <td><div><font>Name</font></div></td>
    </tr> 
</script>

私のJavascriptで:

var template = $('#hidden-template').html();

$('.add').click(function() {
    $('#targetTable').append(template);
});

クラス「追加」のボタンがあり、テンプレートからHTMLを追加します<table id="targetTable">

于 2013-06-08T04:13:21.303 に答える