html += '
' + this.term + '
';html += '
html += '
html += '
//这是直接插入html
document.getElementById("div_id").innerHTML = "你想往div里插入的html代码";
//如果想追加,可以这样
//先保存div中原来的html
var html = document.getElementById("div_id").innerHTML;
//再跟你想追加的代码加到一起插入div中
document.getElementById("div_id").innerHTML = html + "你想往div里追加的html代码";
$(document).ready(function() {
$('#letter-c a').click(function(event) {
event.preventDefault();
$.getScript('c.js');
});
});
将写好的c.js文件放置同一个目录下面
var entries = [
{
"term": "CALAMITY",
"part": "n.",
"definition": "A more than commonly plain and..."
},
{
"term": "CANNIBAL",
"part": "n.",
"definition": "A gastronome of the old school who..."
},
{
"term": "CHILDHOOD",
"part": "n.",
"definition": "The period of human life intermediate..."
}
//省略的内容
];
var html = '';
$.each(entries, function() {
html += '
html += '
html += '
html += '
html += '
});
$('#dictionary').html(html);
//$('#dictionary').append(html);
这里的$('#dictionary').html(html);可以直接将需要的代码放入到指定的div内 (
也可以通过$('#dictionary').append(html);将代码附加到指定的div内 (