[英]How to add a hyperlink column to a table using jquery?
I am building an HTML table (with 4 columns) using below jquery. 我正在使用下面的jQuery构建一个HTML表(具有4列)。 I already added 3 columns.
我已经添加了3列。
How do i add a fourth column to the table in the function below. 如何在下面的函数中向表中添加第四列。 Column is hyperlink with values from the first 3 columns of the table?
列是超链接,其中包含表的前3列中的值?
Expected format of column four : 第四栏的预期格式:
<table style="width:100%"> <tr> <td>COLUMN1</td> <td>COLUMN2</td> <td>COLUMN3</td> <td>COLUMN4</td> </tr> <tr> <td>A1</td> <td>B1</td> <td>C1</td> <td>www.yahoo.com?q1=A1&q2=B1&q3=C1</td> </tr> <tr> <td>A2</td> <td>B2</td> <td>C2</td> <td>www.yahoo.com?q1=A2&q2=B2&q3=C2</td> </tr> <tr> <td>A3</td> <td>B3</td> <td>C3</td> <td>www.yahoo.com?q1=A3&q2=B3&q3=C3</td> </tr> </table>
Here is my my function? 这是我的职能吗?
function testFunction(data, status, jqXHR) {
var testObj = data;
var tempurl= "www.yahoo.ccom";
var table = $("#IdTab");
$.each(testObj.childData, function (i, n) {
var rootmyVal = n.myVal1;
$.each(n, function (e, r) {
table.append("<tr><td>" + rootmyVal + "</td><td>" + r.myVal1 + "</td><td>" + r.myVal2 + "</td></tr>");
});
});
}
Very simple. 很简单。 The same way, use
<a>
tag: 以相同的方式,使用
<a>
标记:
function testFunction(data, status, jqXHR) {
var testObj = data;
var tempurl= "www.yahoo.ccom";
var table = $("#IdTab");
$.each(testObj.childData, function (i, n) {
var rootmyVal = n.myVal1;
$.each(n, function (e, r) {
table.append("<tr><td>" + rootmyVal + "</td><td>" + r.myVal1 + "</td><td>" + r.myVal2 + "</td><td><a href='http://" + tempurl + "'>" + tempurl + "</a></td></tr>");
});
});
}
Also, it looks like the url is just www.yahoo.com
, without the http://
protocol. 另外,该网址似乎只是
www.yahoo.com
,没有http://
协议。 Please ensure you add that before. 请确保您之前添加。 Since you haven't provided the full
data
, I am unable to create a snippet or fiddle. 由于您尚未提供完整的
data
,因此我无法创建摘要或小提琴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.