在html中使用javascript标识选定的td [英] identify the selected td using javascript in html

查看:84
本文介绍了在html中使用javascript标识选定的td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含100行和td的表。如下所示

 < table border =0cellpadding =0cellspacing =0id =artcle-标题> 
< tr>
< td> Artcle细节1< / td>
< / tr>
< tr>
< td> Artcle细节2< / td>
< / tr>
< tr>
< td> Artcle细节3< / td>
< / tr>
< tr>
< td> Artcle细节4< / td>
< / tr>
....
< / table>

当用户点击一个td内容时,我想显示一个单独的内容表格选定的表格。我想在单独的表格中显示内容。我的意思是在选定的表格旁边。
我的问题是,

我如何识别选择了哪个表(无需传递任何参数,例如:funshow(td_id1)等)

有没有人知道这一点?

解决方案

您可以附上点击处理程序到表中的每个 tr 元素。一旦点击此处理程序将被调用,您将能够获得底层的DOM元素。一旦你有了元素,你可以修改它的内容。取决于你是否使用JavaScript框架,实现这个目标的方式会有所不同。例如使用 jQuery

  $(function(){
$('table tr')。click(function(){
$(this).html('< td>一些新内容< / td> ;');
});
});


I have a table which contain 100 rows and td. like see below

<table border="0" cellpadding="0" cellspacing="0" id="artcle-title" >
  <tr>
   <td>Artcle details 1</td>
  </tr>
  <tr>
   <td>Artcle details 2</td>
  </tr>
  <tr>
   <td>Artcle details 3</td>
  </tr>
  <tr>
   <td>Artcle details 4</td>
  </tr>
....
 </table>

When a user click on a td content, i want to display a separate content table with respect to the selected table.i want to display the content in a separate table. I meant out side the selected table. My question is that

How i identify which table is selected ( with out passing any argument eg: funshow(td_id1) etc)

Does any one know this?

解决方案

You could attach a click handler to each tr element in the table. Once clicked this handler will be invoked and you will be able to get the underlying DOM element. Once you have the element you can modify its contents. Depending on whether you are using a javascript framework or not the way to achieve this will vary. For example using jQuery:

$(function() {
    $('table tr').click(function() {
        $(this).html('<td>some new contents</td>');
    });
});

这篇关于在html中使用javascript标识选定的td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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