[英]Generate table from JSON file and use colorbox for each link not working
当我尝试从JSON文件读取表数据时,我发现颜色框不起作用,并且不知道为什么,有什么主意吗? 这是我的代码:
$.getJSON("resource/candidateJob.json",function(data){
$('#candidateTable').empty();
var htmlInfo = '';
htmlInfo +=
'<tr><th>Jobs</th>'+
'<th>Company Name</th>'+
'<th>Industry</th>'+
'<th>Location</th>'+
'<th>Time</th>'+
'<th>Detail</th></tr>';
$.each(data,function(i,item){
//alert(i);
if(i>=(pageIndex-1)*5 && i<(pageIndex)*5){
htmlInfo +=
'<tr><td>'+item['Jobs']+'</td>'+
'<td>'+item['CompanyName']+'</td>'+
'<td>'+item['Industry']+'</td>'+
'<td>'+item['Location']+'</td>'+
'<td>'+item['Time']+'</td>'+
'<td><a class="iframe" v-width="400px" v-height="400px" href="'+item['DetailUrl']+'">Detail</a></td></tr>';
}
});
$('#candidateTable').html(htmlInfo);
})
从代码生成的表如下所示:
<a href=" test.html?jobId=7" v-height="400px" v-width="400px" class="iframe">Detail</a>
Javascript是:
$(document).ready(function(){
$(".iframe").colorbox({
iframe : true,
width : "55%",
height : "75%"
});
})
我从JSON文件中添加表格数据,这会影响颜色框吗? 我只是不明白何时将div放在html中,例如:
<div>
<a class="iframe" href="test.html?jobId=10">Detail</a>
</div>
,并且可以使用,但是当我将其用于表格时,它只是在另一个“标签页”中打开该页面,而不是在灯箱中显示此页面。
只需创建一个用于打开颜色框的函数即可:例如:从json文件生成表格
我有同样的问题,但是很少有更改使它变得简单只需创建一个用于打开colorbox的函数:
function call_cbox(id) {
$.colorbox({ href: "test.html?jobId=" + id, iframe: true, width: "80%", height: "80%", escKey: false, overlayClose: false });
return false;
}
调用函数为
:) 请享用
我希望它为您工作Viresh Rajput Noida
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.