表格加载事件

kimi_xia 2009-04-27 04:36:39
服务器端new Table(),现在需求就是在表格加载时给他每个单元格加一段javascript,使每个单元格加载时都执行一段javascript代码。

table.Rows[i].Cells[j].Attributes.Add("。。。。。","javascript:alert(“aa”)");
应该添加什么事件才能使单元格加载的时候执行alert
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
中年秃头大叔 2009-04-28
  • 打赏
  • 举报
回复
首先table需要加上runat="server" id="tableon"
然后在page_load里面写.
不要把下面放在if(!this.ispostback){}里面,直接放在page_load就可以了。
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < tableon.Rows.Count; i++)
{
for (int j = 0; j < tableon.Rows[i].Cells.Count; j++)
{
this.tableon.Rows[i].Cells[j].Attributes.Add("onclick","javascript:alert('zhanglei')");
}
}
if (!this.IsPostBack)
{

}
}这样就可以了,我测试过,一定可以。
kimi_xia 2009-04-27
  • 打赏
  • 举报
回复
onload我试过了不行的
kimi_xia 2009-04-27
  • 打赏
  • 举报
回复
我比较菜,我想要

script type='text/javascript'>function col() {"+t.Rows[i].Cells[j].Attributes.Add("BgColor", "yellow")+"; }</script>"

想把这单元格变色该怎么拼接字符串
acol 2009-04-27
  • 打赏
  • 举报
回复
for(int i=0;i<table.Rows.Count;i++)
{
for(int j=0;j<table.Rows[i].Cells.Count;j++)
table.Rows[i].Cells[j].Attributes.Add("onload","javascript:alert("alertString")");
}
试试
humin1906 2009-04-27
  • 打赏
  • 举报
回复
换个思路.
后台动态创建一个TD的时候,增加一个JS代码.到最后一起执行.
如:
string strText = "";
for(...)
{
strText += "<script>alerte(i);</script>";
}
page.ClientScript.RegisterStartupScript(Page.GetType(),"",strText);//方法
cytel 2009-04-27
  • 打赏
  • 举报
回复
up

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧