可以动态添加完之后,统一绑定事件
$("#tables td")click(function(){consolelog($(this)text())
})
亦可以每生成一个元素就绑定事件,不过这样你的html需要修改,改为循环插入td
OK
<script type="text/javascript">
var learnnum=0;
var learntemp=0;
function addlearn(){
var learntb = documentgetElementById('learntb');
learnnum += 1;
learntemp += 1;
var learntr = documentcreateElement('tr');
learntrid = "learntr"+learnnum;
var learntd1 = documentcreateElement('td');
learntd1className = "td3";
learntd1innerHTML = "起止时间:";
var learntd2 = documentcreateElement('td');
learntd2className ="td4";
learntd2innerHTML = "<input type='text' name='learntime"+ learnnum +"'/>";
var learntd3 = documentcreateElement('td');
learntd3className = "td3";
learntd3innerHTML = "毕业学校:";
var learntd4 = documentcreateElement('td');
learntd4className ="td4";
learntd4innerHTML = "<input type='text' name='endschool"+ learnnum +"'/>";
var learntd5 = documentcreateElement('td');
learntd5className = "td3";
learntd5innerHTML = "所学专业:";
var learntd6 = documentcreateElement('td');
learntd6className ="td4";
learntd6innerHTML = "<input type='text' name='professional"+ learnnum +"'/>";
var learntd7 = documentcreateElement('td');
learntd7className = "td3";
learntd7innerHTML = "教育方式:";
var learntd8 = documentcreateElement('td');
learntd8className ="td4";
learntd8innerHTML = "<input type='text' name='way"+ learnnum +"'/>";
learntrappendChild(learntd1);
learntrappendChild(learntd2);
learntrappendChild(learntd3);
learntrappendChild(learntd4);
learntrappendChild(learntd5);
learntrappendChild(learntd6);
learntrappendChild(learntd7);
learntrappendChild(learntd8);
learntbappendChild(learntr);
// var lt = documentgetElementById('learntemp');
// ltvalue = learntemp;
}
</script>
<body onload="addlearn();">
This is my JSP page <br>
<table>
<tbody id="learntb">
</tbody>
</table>
</body>
input type="button" value="填加文本框" id="Button1" onclick="Button1_onclick()" /><table id="table1" border="2" cellpadding="2" cellspacing="2"><tbody id="tableBody"> </tbody></table><script language="javascript" type="text/javascript">function Button1_onclick() { var table = documentgetElementById("tableBody"); //找出tableBody var tr = documentcreateElement('tr'); //创建tr tableappendChild(tr); //填加tr到tableBody var td1=windowdocumentcreateElement('td');; //创建td trappendChild(td1); //填加td到tr var elment = '<input type="text" id="txt1" runat="server" />';//定义text控件 td1innerHTML = elment; //填加控件到单元格 }</script>后台查找 string str = ((HtmlInputText)PageFindControl("txt1"))Value; ResponseWrite("<script>alert('"+str+"');</script>");
一个比较笨的方法也是最简单的就是判断选择的值 然后去创建表格比如获取到的值是num
var table="<table>";
for(var i=0;i<num;i++)
{
table+=“<tr><td></td><td></td></tr>”;
}
documentGetElementById("要创建表格的容器ID")InnerHTML=table;
这样就可以了
方法二:
这个方法需要你在页面上先定要表格
function aa(num)//这个是你选择的时候调用的js事件 num为行数
{
for(var i=0;i<num;i++)//判断调用创建表格中行的次数
{
CreatTableRows();
}
}
function CreatTableRows(){
var obj = documentgetElementById("表格ID");
var hangshu = objrowslength;//获取表格现有的行数
var orow = objinsertRow(-1);//在最后一行后面加一行
var ocell = orowinsertCell(); // 在行里面增加一列
var neirong = " 列里面的内容1";
ocellinnerHTML = neirong;
var ocell = orowinsertCell(); // 在行里面增加一列
var neirong = " 列里面的内容2";
ocellinnerHTML = neirong;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>判断</title>
<!--table找到表格 tr:eq(1) 找到第二行,eq从0开始,td:eq(1)找到第二列text()得到信息(深圳网站建设=">
以上就是关于jquery动态添加tr和td到table中,想要点击td得到td对应的值怎么搞全部的内容,包括:jquery动态添加tr和td到table中,想要点击td得到td对应的值怎么搞、JS动态生成td tr、在ASP.NET中怎么获取动态文本框的值(在程序的后台获取)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)