我想在使用 Jquery 动态填充表期间建立链接。我将表数据填充为
trHTML +=
'<tr><td>'+ value['value1'] +
'</td> <td>' + value['value2'] +
'</td> <td>' + value['value3'] +
'</td><td>'.html('<a href="' + "http://www.google.com/" + value['valueLink'] + '">' + "Link" + '</a>')+
'</td></tr>';
但它给出了错误
Uncaught TypeError:
"</td><td>
".html is not a function
最佳答案
您不需要使用.html()
继续字符串连接。
'</td><td>' + '<a href="' + "http://www.google.com/" + value['valueLink'] + '">' + "Link" + '</a>'+
但是,我建议您使用 jQuery( html, attributes ) 创建 HTML更清洁的方法。
var tr = $("<tr>")
var anchor = $("<a>", {
"href" : "http://www.google.com/" + value['valueLink'],
"text" : "Link"
});
var td = $("<td>");
td.append(anchor);
tr.append(td);
关于javascript - 使用 Jquery 动态填充表期间建立链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44002087/