javascript - Using sprintf in jQuery -
this question has answer here:
- javascript equivalent printf/string.format 42 answers
how can use sprintf in jquery?
i'm trying add id
chunk of html returned script
so:
success: function(html){ $('.data').html($.sprintf(html,'test')); },
the html returned large chunk of html i've added %s
sprintf it's replacement.
eg: '<div>welcome blah</div><div>you userid %s</div>'
if it's simple you've described, use string#replace
regular expression (so can use g
flag make replacement happen throughout string):
$('.data').html(html.replace(/%s/g, 'test'));
Comments
Post a Comment