将按钮 href 更改为页面上的其他 href

Change button href to other href on page

我有一个注销的网站 link。

<a href="http://specialuniquelogout.com">Logout</a>

当有人点击此 link 时,会弹出一个通知框询问您 "Are you sure you want to logout?"。他们可以按是或否。如果他们按否,它会关闭通知框。但是我需要将 YES 按钮的 href 属性动态设置为他们单击的原始注销 link 的 href。

我在想也许我可以以某种方式使用 window.location = $this.attr('href'); 但无法弄清楚。

这是我的代码:

<a class="mb-control" data-box="#mb-signout" href="http://UNIQUELOGOUTLINK.com">Logout</a>

<!-- MESSAGE BOX-->
        <div class="message-box animated fadeIn" data-sound="alert" id="mb-signout">
            <div class="mb-container">
                <div class="mb-middle">
                    <div class="mb-title"><span class="fa fa-sign-out"></span> Log <strong>Out</strong> ?</div>
                    <div class="mb-content">
                        <p>Are you sure you want to log out?</p>                    
                        <p>Press No if you want to continue work. Press Yes to logout current user.</p>
                    </div>
                    <div class="mb-footer">
                        <div class="pull-right">
                            <a href="NEED TO PUT THE UNIQUE LOGOUT LINK HERE" class="btn btn-success btn-lg">Yes</a>
                            <button class="btn btn-default btn-lg mb-control-close">No</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- END MESSAGE BOX-->

        <!-- START PRELOADS -->
        <audio id="audio-alert" src="audio/alert.mp3" preload="auto"></audio>
        <audio id="audio-fail" src="audio/fail.mp3" preload="auto"></audio>
        <!-- END PRELOADS -->   

<script>

/* PLAY SOUND FUNCTION */
function playAudio(file){
    if(file === 'alert')
        document.getElementById('audio-alert').play();

    if(file === 'fail')
        document.getElementById('audio-fail').play();    
}
/* END PLAY SOUND FUNCTION */

   /* MESSAGE BOX */
    jQuery(".mb-control").on("click",function(){
        var box = $($(this).data("box"));
        if(box.length > 0){
            box.toggleClass("open");

            var sound = box.data("sound");

            if(sound === 'alert')
                playAudio('alert');

            if(sound === 'fail')
                playAudio('fail');

        }        
        return false;
    });
    jQuery(".mb-control-close").on("click",function(){
       $(this).parents(".message-box").removeClass("open");
       return false;
    });    
    /* END MESSAGE BOX */

</script>

<style>
.message-box {
    display: none;
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.message-box.open {
    display: block;
}

</style>

感谢任何能提供帮助的人!

可以是这样的:

jQuery(".mb-control").on("click", function() {
  var box = $($(this).data("box"));
  if (box.length > 0) {
    box.toggleClass("open");
    box.find('.btn-close').attr('href', this.href);

    var sound = box.data("sound");

    if (sound === 'alert')
      playAudio('alert');

    if (sound === 'fail')
      playAudio('fail');
  }
  return false;
});

我在 class btn-close 添加到 link:

<a href="NEED TO PUT THE UNIQUE LOGOUT LINK HERE" class="btn btn-success btn-lg btn-close">Yes</a>