[英]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.