我有一个需要在电子商务网站的“完成”页面加载的JavaScript,这里是代码:
<script type="text/javascript">
var skulist="",pricelist="",quantitylist="";
for (var i=0; i < OrderDetails.length; i++){
skulist = OrderDetails[i][2]+","+skulist;
pricelist =OrderDetails[i][5]+","+pricelist;
quantitylist =OrderDetails[i][6]+","+quantitylist;
}
skulistLen=skulist.length;
skulist = skulist.slice(0,skulistLen-1);
pricelistLen=pricelist.length;
pricelist = pricelist.slice(0,pricelistLen-1);
quantitylistLen=quantitylist.length;
quantitylist = quantitylist.slice(0,quantitylistLen-1);
document.write("<iframe height='1' width='1' frameborder='0' scrolling='no' src='https://www.emjcd.com/tags/c?containerTagId=49296&ITEM1="+skulist+"&AMT1="+pricelist+"&QTY1="+quantitylist+"&CID=10000171&OID=$(OrderNo)&TYPE=362565438&CURRENCY=USD' name='cj_conversion'></iframe>");
</script>
我需要用jquery调用它...(出于其他原因) - 我这样做是这样的:
<div id="cj-placeholder"><!--placeholder--></div>
<script>
if($.cookie("so-affiliate") ) {
$().ready(function() {
// load external file
//$('#cj-placeholder').load('/v/js/cj.html', function() {
//return;
$.get('/v/js/cj.html')
.success(function(data) {
$('#cj-placeholder').html(data);
});
});
}else{
$('#cj-placeholder').append('.');
}
</script>
问题是,当我这样做时,我得到一个空白页面,只包含cj.html里面的内容(脚本) - 它正在替换订单完成页面而不是附加到它...通过在这里搜索,我了解到如果在页面加载之后像这样调用document.write,那么它将原样替换它,问题是......我该怎么办?
答案 0 :(得分:1)
只需使用append
$('body').append("<iframe height='1' width='1' frameborder='0' scrolling='no' src='https://www.emjcd.com/tags/c?containerTagId=49296&ITEM1="+skulist+"&AMT1="+pricelist+"&QTY1="+quantitylist+"&CID=10000171&OID=$(OrderNo)&TYPE=362565438&CURRENCY=USD' name='cj_conversion'></iframe>");