如何在表格行中单击td来引发事件? [英] How to raise an event on click of td in table row?

查看:104
本文介绍了如何在表格行中单击td来引发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击表格行中的td,我想举起一个事件。我使用了下面的代码,但没有用。



我尝试过:



 <   td     onclick   =  button87()     style   =  font-size:medium; background-color:InfoBackground; >  





  public   void  button87()



{..}

解决方案

以下链接的朋友帮助给你。



编辑小提琴 - JSFiddle [ ^ ]


这是因为您尝试将客户端脚本连接到服务器端脚本 - 而这可以通过Ajax实现请求,这是行不通的。你应该做的是,在客户端创建一个JavaScript函数并用它来处理事件。

  function  button87(){
/ / 此处执行的代码。
}



这将执行一个你的表描述单元格点击它。请注意,在ASP.NET Web窗体中完成附加服务器端事件,您还在其中为元素设置了 runat =server属性。然后,ASP.NET将在服务器端而不是客户端处理该元素。但是,如果您正在处理元素并在客户端处理事件,则必须编写JavaScript(客户端)代码来处理它们。



我这些年来一直信任MDN文件,我建议您这样做, DOM事件处理程序 - Web开发人员指南| MDN [ ^


On click of a td inside a table row I want to raise an event. I used the following code but doesnt work.

What I have tried:

<td onclick="button87()" style="font-size:medium; background-color:InfoBackground;">



public void button87()


{..}

解决方案

HI friend below link help to you.

Edit fiddle - JSFiddle[^]


That is because you are trying to connect the client-side scripts to your server-side scripts — while that is possible through Ajax requests, this is not going to work. What you should have done is, created a JavaScript function on the client-side and used that to handle the event.

function button87 () {
   // Code to execute here.
}


This will be executed one your table description cell gets a click on it. Note that, attaching a server-side event was done in ASP.NET Web Forms where you also had set runat="server" attribute to the elements. ASP.NET would then process the element on the server-side instead of the client-side. But if you are processing the element and handling the events on the client-side, you must write JavaScript (client-side) code to handle them too.

I have trusted MDN documentations for these years and I would recommend the same to you, DOM on-event handlers - Web developer guides | MDN[^]


这篇关于如何在表格行中单击td来引发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆