[英]javascript : function parameters passing?
我的代码如下:
“数据”为:
[{“ DESCRIPTION”:“ sf”,“ Name”:“ Tom”,“ Date”:“ 2014-07-08 10:19:29.0”,“ PICTURES”:[]},{“ DESCRIPTION”:“ sf “,”名称“:” Tom“,”日期“:” 2014-07-08 10:23:33.0“,”图片“:[]},{” DESCRIPTION“:” dfs“,”名称“:” Tom “,” Date“:” 2014-07-08 10:27:20.0“,” PICTURES“:[]},{” DESCRIPTION“:” sfd“,” Name“:” Tom“,” Date“:” 2014 -07-08 10:31:35.0“,”图片“:[{”图片“:” C:\\ Users \\ hanlu Feng \\ workspace \\ .metadata \\ .plugins \\ org.eclipse.wst.server.core \\ tmp0 \\ ServletHtml \\ pictures \\ Tom \\ 2014-07-08-10-31-35 \\ 2012042622442667.jpg“},{” PICTURE“:” C:\\ Users \\ 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;
}
});
}
当我调试它时,出现错误“未捕获的SyntaxError:意外的数字”。 我认为错误在于代码中:
var p ="<p><u><font size='2' color='blue' onclick='requestPictures("+url+"," +userName+", "+reportTime+")' style='cursor:pointer'>Check Pcitures</font></u></p>";
我尝试了很多方法,但是没有用。 我在此链接中使用该方法: 参数传递
错误仍然存在。我不知道为什么?
我想像这样创建一个表:
首先,我的解决方案将不包括内联样式,字体标签或下划线标签。 我建议您将所有这些都放在一个类中。
代替插入纯HTML,您应该创建一个对象,绑定click事件,然后将其附加到单元格。
var p = $("<p class='picture-link'>Check Pictures</p>");
p.click(function(){requestPictures(url, userName, reportTime);});
$(cell).append(p);
这就是我要做的。
正如我所说,您必须创建课程
我也添加了样式。
.picture-link{
text-decoration: underline;
color: blue;
cursor: pointer;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.