我的代码如下:
"数据"是:
[{"说明":" SF""名称":"汤姆""日期&#34 ;: " 2014-07-08 10:19:29.0"," PICTURES":[]},{" DESCRIPTION":" sf" ,"姓名":" Tom","日期":" 2014-07-08 10:23:33.0",&#34的照片;照片":[]},{"说明":" DFS""名称":"汤姆"&#34 ;日期":" 2014-07-08 10:27:20.0","图片":[]},{"说明":&# 34; sfd","姓名":" Tom","日期":" 2014-07-08 10:31:35.0&# 34;," PICTURES":[{" PICTURE":" C:\ Users \ hanlu Feng \ workspace \ .metadata \ .plugins \ org.eclipse.wst.server 。核心\ TMP0 \ ServletHtml \图片\汤姆\ 2014-07-08-10-31-35 \ 2012042622442667.jpg"},{" PICTURE":" C:\用户\ hanlu Feng \ workspace \ .metadata \ .plugins \ org.eclipse.wst.server.core \ tmp0 \ ServletHtml \ pictures \ Tom \ 2014-07-08-10-31-35 \ 833344_1071288421.jpg"}]} ]
//Code 1
function dynamicReport(data){
var table = document.getElementById("erroreport");
if(table.rows.length==0){
for(var i=0;i<=data.length;i++){
if(i==0){
var row = table.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = titleName;
cell = row.insertCell(1);
cell.innerHTML = titleTime;
cell = row.insertCell(2);
cell.innerHTML = titleDescription;
cell = row.insertCell(3);
cell.innerHTML = titleImages;
}else{
var row = table.insertRow(i);
var cell = row.insertCell(0);
cell.innerHTML= data[i-1].Name;
cell = row.insertCell(1);
cell.innerHTML = data[i-1].Date;
var description = data[i-1].DESCRIPTION;
if(description.length>7){
description = description.substring(0,7)+"..."
}
cell = row.insertCell(2);
cell.innerHTML=description;
var userName = data[i-1].Name;
var reportTime= data[i-1].Date;
var url = "selectionShow";
var p ="<p><u><font size='2' color='blue' onclick='requestPictures("+url+"," +userName+", "+reportTime+")' style='cursor:pointer'>Check Pcitures</font></u></p>";
cell = row.insertCell(3);
cell.innerHTML = p;
}//end else
}//end for
}//end if
}
// code 2
function requestPictures(listUrl,name,time){
var var1=name;
var var2 = time;
$.ajax({
cache : false,
type : "POST",
dataType : "json",
url : listUrl,
//data : $("#ajaxFrm").serialize(),
data : {command:"images","name":name,"time":time},
async : false,
error : function(request) {
waidAni();
if(request.status ==202){
alert(request.responseText);
}else
alert("Request Error");
},
success : function(data) {
waidAni();
//alert(data);
window.location.href= data;
}
});
}
当我调试它时,出现错误&#34; Uncaught SyntaxError:意外的数字&#34;。 我认为错误在代码中:
var p ="<p><u><font size='2' color='blue' onclick='requestPictures("+url+"," +userName+", "+reportTime+")' style='cursor:pointer'>Check Pcitures</font></u></p>";
我尝试了很多方法,它没有用。我使用此链接中的方法: parameters passing
错误仍然存在。我不知道为什么?
我想创建一个像这样的表:
答案 0 :(得分:0)
首先,我的解决方案不包括内联样式,字体标记或下划线标记。我建议你把所有这些都放在课堂上。
您应该创建一个对象,绑定click事件,然后将其附加到单元格,而不是插入纯html。
var p = $("<p class='picture-link'>Check Pictures</p>");
p.click(function(){requestPictures(url, userName, reportTime);});
$(cell).append(p);
我就是这样做的。
正如我所说,你必须创建班级
Here is a fiddle that demonstrates what I'm doing
我也添加了一种风格。
.picture-link{
text-decoration: underline;
color: blue;
cursor: pointer;
}