1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSで簡単なテンプレートファイルを作る時のメモ

Last updated at Posted at 2013-07-08
<script type="text/template" id="hogeTemplate">
    <div id="hoge">
        <a href="%s">%s</a>
    </div>
</script>
var sprintf = function(text) {
    var i = 1, args = arguments;
    return text.replace(/%s/g, function() {
        return (i < args.length) ? args[i++] : '';
    });
};

var template = sprintf($('#hogeTemplate').text(), url, text);
$('body').append(template);
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?