简体   繁体   English

表格单元格中链接的警报值

[英]Alert value of a link in a table-cell

here is my fiddle . 这是我的小提琴 It shows two headlines and two tables with table-cells. 它显示了两个标题和两个带有表格单元的表格。 What I'm trying to do is to alert the values in the table-cells below one headline when clicking a headline. 我想做的是单击标题时提醒一个标题下方的表格单元中的值。

Example: If one clicks on Headline1 there should be an alert with the values 5 and 2. If one clicks on Headline2 there should be an alert with the value 6. 示例:如果单击Headline1,则应显示值为5和2的警报。如果单击Headline2,则应显示值为6的警报。

My problem is that I don't get the values. 我的问题是我没有得到值。 Have you got an idea? 你有个主意吗?

Thanks for sharing it. 感谢分享。

Try this: 尝试这个:

$(".bold").click(function() {
    var arr = [];
    $(this).next().find('a').each(function(){
        arr.push($(this).html());
    });
    alert(arr.join(', '));
});

http://jsfiddle.net/YAL7L/13/ http://jsfiddle.net/YAL7L/13/

I would sugest altering the markup. 我建议修改标记。 Otherwise I think you'll have a hard time getting the result you want. 否则,我认为您将很难获得想要的结果。

HTML: HTML:

    <div class="bold">Headline1
    <table>
    <tr>
        <td><a href="">5</a></td>
        <td><a href="">2</a></td>
    </tr>
    </table>
</div>
<div class="bold">Headline2
    <table>
    <tr>
        <td>
            <a href="">6</a>
        </td>
    </tr>
    </table>
</div>

then your javascript could look like this: 那么您的JavaScript可能如下所示:

$(".bold").click(function() {$(this).find("a").each(function(){alert($(this).html());}); });

I'm not saying it's the best solution - but it works ;-) 我并不是说这是最好的解决方案-但它有效;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM