我想现在有没有像JavaScript的document.write()的任何功能,而不是替换元素它追加他们,因为我建立一个功能,用代码替换用户输入,它的工作但问题不在于在特定位置添加代码,而是替换所有页面内容。替换为document.write但附加功能
我的功能代码。
function one(json) {
var j = 0;
var img = new Array();
var maxpost=json.feed.entry.length;
for (var i = 0; i < numposts1; i++) {
var entry = json.feed.entry[i];
var posttitle = entry.title.$t;
var pcm;
var posturl;
var postAuthor = entry.author[0].name.$t;
var postLabels = entry.category[1].term;
if ((i>0)&&(i<maxpost)) {
var trtd = '<a href="'+posturl+'">'+posttitle+'</a><h2>'+posttitle+'</h2> <span>'+postAuthor+'</span><span>'+postLabels+'</span><div>'+img[i]+'</div>';
document.write(trtd);
}
j++;
}
}
,这是代码
$(document).ready(function(){
$('.widget-content').each(function(){
var b = $(this).html();
var a = b.match(/[^[\]]+(?=])/g);
var code = $('#myscript').attr('src');
var script= document.createElement('script');
script.type='text/javascript';
script.src=code;
$('.HTML').append("<script id='myscript' src='/feeds/posts/default/-/Break?published&alt=json-in-script&callback=one'><\/script>");
});
});
在jQuery中大约有四十种这样的方法。 – adeneo
@adeneo你可以给一些例子 – abdel