当我应用以下脚本时,它在输出中随机出现“未定义”。我已经检查过,它应该是由 javascript 引起的。我可以知道可能是什么错误吗?
<div id="changeImgNews"></div>
<script language=Javascript>
var countNum = <{$block.countNum}>;
var checkRepNews = 1;
var ranNumNews = 0;
var ranContentNews = "";
var arti_name = new Array();
var arti_img = new Array();
var arti_id = new Array();
var arti_model = new Array();
var arti_desc = new Array();
<{foreach from=$block.news item=arti key=count}>
arti_name[<{$count}>] = "<{$arti.name}>";
arti_img[<{$count}>] = "<{$arti.img}>";
arti_id[<{$count}>] = "<{$arti.id}>";
arti_model[<{$count}>] = "<{$arti.model}>";
arti_desc[<{$count}>] = "<{$arti.desc}>";
<{/foreach}>
function randomImageNews()
{
ranNumNews = Math.round(Math.random()*countNum);
while (ranNumNews == checkRepNews){
ranNumNews = Math.round(Math.random()*countNum+1);
};
checkRepNews = ranNumNews;
ranContentNews = "<a href='<{$portal_url}>/modules/content/item.php?itemid=16' title='"+arti_name[ranNumNews]+"'><img src='<{$portal_url}>/modules/news/images/news"+arti_img[ranNumNews]+"' style='border: 1px solid #000000; ' / width='220' height='220'></a><br /><div style='text-align:left; width:220px;'>"+arti_model[ranNumNews]+" - <a href='<{$portal_url}>/modules/content/item.php?itemid=16'>"+arti_name[ranNumNews]+"</a>";
document.getElementById('changeImgNews').innerHTML = ranContentNews;
setTimeout("randomImageNews();", 8000);
}
randomImageNews();
</script>