如何使用通过javascript在客户端创建的元素 [英] How to work with elements which were created in Client side through javascript
本文介绍了如何使用通过javascript在客户端创建的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function addRow(id){
alert(id);
var x = document .getElementById( CphrEMS_tblnew);
var node = x.rows [ 0 ]。cells [ 0 ]。cloneNode( true );
node.id = 2 ;
x.appendChild(node); // 将节点或行添加到表中
返回 false ;
}
我使用上面的代码在客户端创建元素
如何
在代码背后访问这些新创建的元素?
以及它们在Post Back中消失了
解决方案
在这个场景中我建议你使用Ajax GET / POST进行客户端编程方法,
当你动态生成元素然后给它们一个唯一的id
并且对于数据操作你可以使用ajax方法进行绑定或插入,更新删除而不回发一页
所以你的元素不清楚.. :)
更多信息请参阅我的提示/技巧,
它不是你想要的,但我在gridview中动态生成文本框并使用ajax post方法绑定它们... :)
[ ^ ]
使用AJAX绑定Gridview [ ^ ]
function addRow(id) {
alert(id);
var x = document.getElementById("CphrEMS_tblnew");
var node = x.rows[0].cells[0].cloneNode(true);
node.id = 2;
x.appendChild(node); //add the node or row to the table
return false;
}
I'm using the above Code to create elements in Client Side
How to
Access these Newly Created Elements In Code Behind ?
and also they Were Disappearing in Post Back
解决方案
In this scenerio i am suggest you to use client side programming using Ajax GET/POST method,
When you are generate elements dynamically then give them all a unique id
and for data manipulations you can use ajax methods for binding or insert,update delete without postback of a page
so your elements doesnt clear .. :)
for more info see my tip/trick,
it is not exactly whatever you want but i have generate textboxes dynamically in gridview and bind them using ajax post method... :)
Expandable Table like Gridview[^]
Bind Gridview using AJAX [^]
这篇关于如何使用通过javascript在客户端创建的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文