[英]alert with jquery for multi table
I have the following: 我有以下几点:
$columns = array('aaa','bbb','ccc','ddd');
$num_cols = count(columns);
echo "<table>";
echo "<tr>";
foreach($columns as $col)
{
echo "<td>$col</td>";
}
echo "</tr>";
for($i=1;$i<4;$i++)
{
echo "<tr>";
for($j=0;$j<$num_cols;$j++)
{
echo "<td class='click' from=???>$i</td>";
}
echo "</tr>";
}
echo "</table>";
this generated for me: 这为我产生了:
aaa | bbb | ccc | ddd
1 | 1 | 1 | 1
2 | 2 | 2 | 2
3 | 3 | 3 | 3
i would like add for this alert jquery - if i click for example 2 from aaa i have receive alert (2 from a); 我想为此警报jquery添加-如果我单击例如来自aaa的2,我将收到警报(来自a的2);
i use jquery: 我使用jQuery:
$(".click").click(function(){
alert($(this).html + "from" + ???);
})
is this possible? 这可能吗?
First note that html
is a function. 首先请注意
html
是一个函数。 Also, on
is the preferred way to add events as of jQuery 1.7 另外,
on
jQuery 1.7开始, on
是添加事件的首选方式
I would put your header cells in <th>
tags, then do: 我会将标题单元格放在
<th>
标记中,然后执行以下操作:
$(document).on("click", "td", function () {
var index = $(this).parent().find(this).index();
alert($(this).html() + "from" + $("table th").eq(index).html());
});
Or, if you don't want to put your first row in <th>
tags, this will work too: 或者,如果您不想将第一行放在
<th>
标记中,这也将起作用:
$(document).on("click", "td", function () { var index = $(this).parent().find(this).index(); alert($(this).html() + "from" + $("table tr:first td").eq(index).html()); }); $(document).on(“ click”,“ td”,function(){var index = $(this).parent()。find(this).index(); alert($(this).html() +“ from” + $(“ table tr:first td”)。eq(index).html());});
And you better use this using jQuery live , 而且您最好使用jQuery live来使用它,
$(".click").live("click", function(){
alert($(this).html + "from" + ???);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.