开发者

Confirm box when link is clicked

开发者 https://www.devze.com 2022-12-28 01:12 出处:网络
<script type=\"text/javascript\"> $(\"a.route\").live(\'click\', function() { // live is better $(\"#results\").load( $(thi开发者_运维问答s).attr(\'href\') );
<script type="text/javascript">
    $("a.route").live('click', function() { // live is better
        $("#results").load( $(thi开发者_运维问答s).attr('href') );
        return false;
    });
</script>  

That's the code, how can I incorporate the code you just gave me?


The Confirm dialog returns true if the user clicks the OK button, or false if the user clicks on the Cancel button. You can use this value to trigger your script if they've clicked OK like this:

<script type="text/javascript">
    $("a.route").live('click', function() {
        if (confirm("Are you sure?")) {
            $("#results").load( $(this).attr('href') );
        }
        return false;
    });
</script>


if you want to use a custom box you could do it like that:

test link: http://jsfiddle.net/myDry/

function blockmeornot(extlink) {
    var oherf = $(extlink).attr('href')
    var msgboxID = 'areyousure'
    var msgbox = '<div id="' + msgboxID +'"><div><p> put your message here </p><a class="yes" href="' + oherf + '"> yes </a> <a class="no" href="#"> no </a></div></div>'
    $('body').append(msgbox)
    $('#' + msgboxID + ' a.no').live('click', function(){ $('#' + msgboxID).fadeOut(400, function(){$(this).remove()}) })
}

$('a.external').click(function(){ blockmeornot(this); return false })
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号