javascript - 如何为每个超链接检测某个 HREF

标签 javascript jquery

             $(document).ready(function(){
                $(".item_delete").easyconfirm({locale: {
                        title: 'Select Yes or No', 
                        text: 'Do you really want to delete this product?',
                        button: ['No','Yes']
                }});
                $(".item_delete").click(function(){
                    $(location).attr('href',$(this).attr("href"));
                });
            });

上面的代码是我想要运行的代码,但它不适用于多个链接,可能是因为代码无法确定选择哪个 HREF。

            <a href="<?php echo "index.php?module=account&del_product=".$row['product_code']; ?>" class="item_delete ui-icon ui-icon-trash"></a>

如果链接有如下多个 href,jquery 如何检测我点击的特定链接?

             <a href="index.php?module=account&del_product=1"></a>
             <a href="index.php?module=account&del_product=2"></a>
             <a href="index.php?module=account&del_product=3"></a>
             <a href="index.php?module=account&del_product=4"></a>
             <a href="index.php?module=account&del_product=5"></a>
             <a href="index.php?module=account&del_product=6"></a>

感谢您的合作...

顺便说一下,我正在为 jQuery 使用这个“简单确认对话框”插件 - http://projectshadowlight.org/jquery-easy-confirm-dialog/

最佳答案

使用$(this)可以得到当前点击的超链接的href

    $("a.item_delete").on("click", function(){
        console.log($(this).attr("href"));
    });

关于javascript - 如何为每个超链接检测某个 HREF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10021854/

相关文章:

javascript - JS/jQuery - 悬停时仅播放一次 GIF

Javascript 添加 e.preventDefault();编写脚本

javascript - 为什么 jQuery 不能与 Bootstrap 4 alpha 6 一起使用?

javascript - 如何使随机文本在悬停在按钮上时旋转,就像 google "I am feeling lucky button"一样,谁能帮我?

javascript - ng-repeat 没有父容器

javascript - 在 JS 中 trim 数组

jquery - 如果父级有某个类,则将类添加到父级标记

javascript - Ember-data:加载一对一相关模型

javascript - 如何在重新加载页面后保存按钮的值?

javascript - 谷歌广告 : tracking events