Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery确认库找到正确的链接_Jquery_Hyperlink_Target - Fatal编程技术网

如何使用jquery确认库找到正确的链接

如何使用jquery确认库找到正确的链接,jquery,hyperlink,target,Jquery,Hyperlink,Target,我正在使用库来确认单击链接时用户的操作。当只有一个链接存在时,下面的代码工作得很好,但是我的页面上有数百个链接需要能够使用这个确认对话框 $('.confirm').confirm({ text: "By clicking yes you are confirming that you want to remove this category and ALL PRODUCTS that are associated with it. Do you wish to con

我正在使用库来确认单击链接时用户的操作。当只有一个链接存在时,下面的代码工作得很好,但是我的页面上有数百个链接需要能够使用这个确认对话框

$('.confirm').confirm({
            text: "By clicking yes you are confirming that you want to remove this category and ALL PRODUCTS that are associated with it.  Do you wish to continue?"
            });

对话功能正常,但当我确认后,它会将我发送到错误的链接。我已经能够确定,它只是在DOM中查找.confirm的第一个实例并激活该链接。虽然它对我来说是有意义的,但我需要知道如何定位正确的链接。我曾考虑过为所有链接动态生成id,但这似乎是解决此问题的一个非常糟糕的方法。我也知道,在不使用这个库的情况下,有许多不同的方法可以解决这个问题,但我对它们不感兴趣,因为这个特定的库适合我的主题

我不确定该插件是否正常运行,但您可以尝试以下方法:

$('.confirm').each(function() {
   $(this).confirm({
            text: "By clicking yes you are confirming that you want to remove this category and ALL PRODUCTS that are associated with it.  Do you wish to continue?"
            });
});

jquery插件应该绑定到每个单独的元素,这样您的代码就可以工作了。你确定链接是正确的吗?是的,我100%确定链接是正确的,因为我已经检查了它们,如果删除了此脚本,它们将在未经确认的情况下正常工作。这很有效。具有讽刺意味的是,我之前尝试过类似的方法,但一定是语法错误。谢谢你的帮助。我有点困惑,因为每个jquery插件都实现了类似的东西,但我很高兴我能提供帮助