繁体   English   中英

为锚添加点击事件

[英]Add click event for anchor

我想显示表的标题列文本(存在于锚中),并将警报事件绑定到锚。 我尝试了一些东西但是没有用

   <table style="width:20%;border:1;border-style:solid"   >
        <tr>
            <td>
               <a href="#">Header 1</a> </td>
            <td>
                <a href="#">Header 2</a></td>
            <td>
               <a href="#">Header 3</a></td>
        </tr>
        <tr>
            <td>
                R1C1</td>
            <td>
                R1C2</td>
            <td>
                R1C3</td>
        </tr>
        <tr>
            <td>
                R2C1</td>
            <td>
                R2C2</td>
            <td>
                R2C3</td>
        </tr>
    </table>

请找到使用的jQuery

  <script type="text/javascript">

        $(document).ready(function () {
            //should display Header 1, Header 2, Header 3
            $("table tr td a").each(alert($(this).text()));
            //Add click event for anchor
            $("table tr td a").click(function (e) { alert(); })
        });

    </script>
    $(document).ready(function () {
        //should display Header 1, Heder 2, Header 3
        $("table tr td a").each(function() {// need a function here
            alert($(this).text())
         });
        //Add click event for anchor
        $("table tr td a").click(function (e) { alert($(this).text()); return false;})
    });

暂无
暂无

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

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