Html标题属性值未正确应用于td元素动态?

时间:2016-09-28 07:05:51

标签: javascript jquery html dynamic html-table

这里我使用JSON Data动态生成表。表生成很好,现在我想在特定字段的title属性中显示值。

例如。我需要在客户端代码

的title属性上显示“client”值

MY JQUERY Code

var data = [
    {
        "Client Code": "ADV",
        "Project Code": "-001",
        "Work Description": "test record 1",
        "Location": "O",
        "Date": "28-09-2016",
        "Duration": "1.50",
        "Recordid": "43887",
        "Client": "Adivtek Parcel Services",
        "Projects": "Hello",
        "Delete": "Delete",
        "StatusFlag": "0",
        "RowNumber": "1"
  }
];

var cont = parent.find("tbody");
var html = "<tr>";
var td = "";
var title_string = "";
for (var i = 0; i < cols.length; i++)
{
    if (cols[i] == "Client Code")
    {
        title_string = data.Client;
    }
    else if (cols[i] == "Project Code")
    {
        title_string = data.Projects;
    }
    else
        title_string = "";
    td = "<td title=" + title_string + ">";

    html += td + data[cols[i]] + "</td>";
}
html += "</tr>";
cont.append(html);

现在我的输出是 enter image description here

现在问题是标题显示良好,但它不能取空格后的值,这意味着我在客户代码的标题属性中显示标题客户名称“Adivtek包裹服务”。只需要 Adivtek ......?

任何人都建议或给出答案? 提前致谢

1 个答案:

答案 0 :(得分:2)

试试这个,将字符串放在单个撇号之间可能有帮助

td="<td title='"+ title_string +"'>";