简体   繁体   中英

Html title Attribute value not applied properly for td element Dynamically?

Here I am generating the table dynamically using JSON Data. Table Generating is fine, now i want to show the values in title attribute in specific field.

For Example. i need to show "client" value on title attribute of client Code

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);

Now My Output is 在此处输入图片说明

Now Problem is the title as showed well but it can't takes the values after the space, that means i display the title Client Name "Adivtek Parcel Services" in title attribute for client Code. it takes Adivtek only...?

Anyone please suggest or give answers ? Thanks in Advance

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM