如何使用json在运行时绑定表中的链接按钮? [英] how to bind a link button in table at run time using json?
问题描述
这是我的代码来自这段代码我想绑定链接按钮,我需要对链接按钮执行操作
''''''''''''''' '
$(文件)。'''' ready(function(){
// GetDetails();
$ .ajax({
类型:" POST",
contentType:" application / json; charset = utf-8",
dataType:" json" ;,
url:" JSON.aspx / LoadData",
data:" {}",
success:function(响应){
BindTable(response.d);
},
失败:功能(数据){
警报('错误');
}
});
});
功能BindTable (山姆){
var div = document.getElementById('divTbl');
试试{
var tbl = document.getElementById('newtable');
if(tbl.id!= null){
div.removeChild( tbl);
}
}
catch(e){
}
var tab = document.createElement('table');
tab.setAttribute(' id','newtable');
tab.setAttribute('cellpadding','0');
tab.setAttribute('cellspacing','0');
tab.setAttribute('width','100%');
var body = document.createElement('tbody');
var trow,cell;
var i;
$ .each(sam,function(index,emp){
trow = document.createElement(" tr");
for(i = 0;我< 4; i ++){
cell = document.createElement('td');
cell.setAttribute('width','200px') ;
var id = emp.Id;
var name = emp.Name;
var code = emp.Code;
var add = emp.Address;
var email = emp.Email;
if(i == 0){
var hfd = document.createElement('input');
hfd.setAttribute('type ','隐藏');
hfd.setAttribute('id','hfd_'+ id);
hfd.setAttribute('value',id);
cell.setAttribute(" width"," 200px")
cell.appendChild(hfd);
cell.appendC hild(document.createTextNode(name));
}
else if(i == 1 ){$ / $
cell.setAttribute(" width"," 200px");
cell.appendChild(document.createTextNode(code) ));
}
否则if(i == 2){
var span = document.createElement('span');
cell.setAttribute(" width"," 200px");
span.setAttribute( " display"," inline-block");
span.appendChild(document.createTextNode(email));
cell.appendChild(span);
}
否则if(i == 3){
cell。 setAttrib ute(" width"," 200px");
cell.appendChild(document.createTextNode(add));
}
trow.appendChild(cell);
}
body.appendChild(trow);
});
tab.appendChild(body);
div.appendChild(tab);
}
This is my code from this code i wanna bind link button and i need to do perform action for the link button
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
$(document).ready(function () {
//GetDetails();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "JSON.aspx/LoadData",
data: "{}",
success: function (response) {
BindTable(response.d);
},
failure: function (data) {
alert('error');
}
});
});
function BindTable(sam) {
var div = document.getElementById('divTbl');
try {
var tbl = document.getElementById('newtable');
if (tbl.id != null) {
div.removeChild(tbl);
}
}
catch (e) {
}
var tab = document.createElement('table');
tab.setAttribute('id', 'newtable');
tab.setAttribute('cellpadding', '0');
tab.setAttribute('cellspacing', '0');
tab.setAttribute('width', '100%');
var body = document.createElement('tbody');
var trow, cell;
var i;
$.each(sam, function (index, emp) {
trow = document.createElement("tr");
for (i = 0; i < 4; i++) {
cell = document.createElement('td');
cell.setAttribute('width', '200px');
var id = emp.Id;
var name = emp.Name;
var code = emp.Code;
var add = emp.Address;
var email = emp.Email;
if (i == 0) {
var hfd = document.createElement('input');
hfd.setAttribute('type', 'hidden');
hfd.setAttribute('id', 'hfd_' + id);
hfd.setAttribute('value', id);
cell.setAttribute("width", "200px")
cell.appendChild(hfd);
cell.appendChild(document.createTextNode(name));
}
else if (i == 1) {
cell.setAttribute("width", "200px");
cell.appendChild(document.createTextNode(code));
}
else if (i == 2) {
var span = document.createElement('span');
cell.setAttribute("width", "200px");
span.setAttribute("display", "inline-block");
span.appendChild(document.createTextNode(email));
cell.appendChild(span);
}
else if (i == 3) {
cell.setAttribute("width", "200px");
cell.appendChild(document.createTextNode(add));
}
trow.appendChild(cell);
}
body.appendChild(trow);
});
tab.appendChild(body);
div.appendChild(tab);
}
推荐答案
(文件).ready(function(){
// GetDetails();
(document).ready(function () {
//GetDetails();
.ajax({
类型:" ; POST",
contentType:" application / json; charset = utf-8",
dataType:" json",
url:" JSON.aspx / LoadData",
data :" {}",
成功:函数(响应){
BindTable(response.d);
},
失败:函数(数据){
alert('错误');
}
});
});
功能BindTable(山姆){
var div = document.getElementById('divTbl');
试试{
var tbl = document.getElementById('newtable');
if(tbl.id!= null){
div.removeChild (tbl);
}
}
catch(e){
}
var tab = document.createElement('table');
tab.setAttribute(' id','newtable');
tab.setAttribute('cellpadding','0');
tab.setAttribute('cellspacing','0');
tab.setAttribute('width','100%');
var body = document.createElement('tbody');
var trow,cell;
var i;
.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "JSON.aspx/LoadData",
data: "{}",
success: function (response) {
BindTable(response.d);
},
failure: function (data) {
alert('error');
}
});
});
function BindTable(sam) {
var div = document.getElementById('divTbl');
try {
var tbl = document.getElementById('newtable');
if (tbl.id != null) {
div.removeChild(tbl);
}
}
catch (e) {
}
var tab = document.createElement('table');
tab.setAttribute('id', 'newtable');
tab.setAttribute('cellpadding', '0');
tab.setAttribute('cellspacing', '0');
tab.setAttribute('width', '100%');
var body = document.createElement('tbody');
var trow, cell;
var i;
.each( sam,function(index,emp){
trow = document.createElement(" tr");
$ (b = b;(i = 0;我< 4; i ++){
cell = document.createElement('td');
cell.setAttribute('width','200px') ;
var id = emp.Id;
var name = emp.Name;
var code = emp.Code;
var add = emp.Address;
var email = emp.Email;
if(i == 0){
var hfd = document.createElement('input');
hfd.setAttribute('type ','隐藏');
hfd.setAttribute('id','hfd_'+ id);
hfd.setAttribute('value',id);
cell.setAttribute(" width"," 200px")
cell.appendChild(hfd);
cell.appendC hild(document.createTextNode(name));
}
else if(i == 1 ){$ / $
cell.setAttribute(" width"," 200px");
cell.appendChild(document.createTextNode(code) ));
}
否则if(i == 2){
var span = document.createElement('span');
cell.setAttribute(" width"," 200px");
span.setAttribute( " display"," inline-block");
span.appendChild(document.createTextNode(email));
cell.appendChild(span);
}
否则if(i == 3){
cell。 setAttrib ute(" width"," 200px");
cell.appendChild(document.createTextNode(add));
}
trow.appendChild(cell);
}
body.appendChild(trow);
});
tab.appendChild(body);
div.appendChild(tab);
}
.each(sam, function (index, emp) {
trow = document.createElement("tr");
for (i = 0; i < 4; i++) {
cell = document.createElement('td');
cell.setAttribute('width', '200px');
var id = emp.Id;
var name = emp.Name;
var code = emp.Code;
var add = emp.Address;
var email = emp.Email;
if (i == 0) {
var hfd = document.createElement('input');
hfd.setAttribute('type', 'hidden');
hfd.setAttribute('id', 'hfd_' + id);
hfd.setAttribute('value', id);
cell.setAttribute("width", "200px")
cell.appendChild(hfd);
cell.appendChild(document.createTextNode(name));
}
else if (i == 1) {
cell.setAttribute("width", "200px");
cell.appendChild(document.createTextNode(code));
}
else if (i == 2) {
var span = document.createElement('span');
cell.setAttribute("width", "200px");
span.setAttribute("display", "inline-block");
span.appendChild(document.createTextNode(email));
cell.appendChild(span);
}
else if (i == 3) {
cell.setAttribute("width", "200px");
cell.appendChild(document.createTextNode(add));
}
trow.appendChild(cell);
}
body.appendChild(trow);
});
tab.appendChild(body);
div.appendChild(tab);
}
这篇关于如何使用json在运行时绑定表中的链接按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!