ここでjsfiddleを作成しました
http://jsfiddle.net/rtP9c/8/
それが役立つかどうかを確認してください
<div id="email">
To <div class="template name">2</div><br/>
I am Jack's email template. I am a unique and beautiful <div class="template insect"></div>. Did you know that you are not your <div class="template possession"></div>.<br>
From <div class="template from"></div>
</div>
JS:
var email = {
name : 'Tyler',
insect : 'butterfly',
possession : 'Khaki Pants',
from : 'Narrator'
};
$('.template').each(function(k,v){
var template = $(this).attr('class').split(' ')[1];
$(this).text(email[template]);
});
またはAJAXを介して:
$.ajax({
url: 'http://site.com'
dataType: 'json',
data : data,
success: function(data) {
$('.template').each(function(k,v){
var template = $(this).attr('class').split(' ')[1];
$(this).text(data[template]);
});
},
error: function(status) {
console.log(status);
}
});