Javascript 只有在用户确认后才能打开多重链接

Javascript 只有在用户确认后才能打开多重链接,javascript,jquery,hyperlink,Javascript,Jquery,Hyperlink,我正在尝试打开多个链接以打开弹出/用户确认窗口,如“您确定要打开窗口吗?”如果是,则在新窗口中打开链接 <li class="footerlink"><a href="http://www.google.com">Link 1</a></li> <li class="footerlink"><a href="http://www.yahoo.com">Link 2</a></li> <li cl

我正在尝试打开多个链接以打开弹出/用户确认窗口,如“您确定要打开窗口吗?”如果是,则在新窗口中打开链接

<li class="footerlink"><a href="http://www.google.com">Link 1</a></li>
<li class="footerlink"><a href="http://www.yahoo.com">Link 2</a></li>
<li class="footerlink"><a href="http://www.bbc.co.uk">Link 3 </a></li>
  • 在JQuery/javascript中是否可以处理多个链接

    谢谢

  • $(“.footerlink”)。单击(函数(e){ e、 preventDefault()//这将阻止从`a`标记打开其href var r=确认(“你确定吗?”); 如果(r==true){ var link=document.createElement('a'); link.href=$(this.find('a').attr(“href”); link.target=“_blank”; link.click(); } });
    如果您希望得到以下简单的确认(是/否),可以使用内联javascript:

  • 或者您可以为更复杂的对话框编写单独的函数(例如引导模式)。在这种情况下,您可以使用自己的自定义函数替换返回确认(“消息”):

    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.google.com">Link 1</a></li>
    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.yahoo.com">Link 2</a></li>
    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.bbc.co.uk">Link 3 </a></li>
    
    function customConfirm(e) {
        // Do your thing!
    }
    
  • 功能自定义确认(e){ //做你的事! }
    谢谢您的回复。。但是这个函数会在整个“a”标签上工作吗?我只想要页脚链接上的确认窗口,它不会对整个标签起作用。。为页脚链接指定一个特定的类名,然后像`$(“.footerClass”)那样调用;我不明白你在说什么(显示错误“e.preventdefault不是函数”Anoop LLits preventdefault()…D大写)
    <li class="footerlink"><a onclick="return confirm('Are you sure?')" href="http://www.google.com">Link 1</a></li>
    <li class="footerlink"><a onclick="return confirm('Are you sure?')" href="http://www.yahoo.com">Link 2</a></li>
    <li class="footerlink"><a onclick="return confirm('Are you sure?')" href="http://www.bbc.co.uk">Link 3 </a></li>
    
    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.google.com">Link 1</a></li>
    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.yahoo.com">Link 2</a></li>
    <li class="footerlink"><a onclick="return customConfirm(this)" href="http://www.bbc.co.uk">Link 3 </a></li>
    
    function customConfirm(e) {
        // Do your thing!
    }