【问题标题】:How to achieve a return confirm like dialog but using jgrowl?如何实现返回确认,如对话框但使用 jgrowl?
【发布时间】:2011-10-26 06:10:37
【问题描述】:

我正在使用论坛脚本(简单机器论坛) 它正在使用这种 javascript 确认消息:

<a href="http://domain.net/index.php?action=deletemsg;topic=1.0;msg=1;c6c7a67=f9e1fd867513be56e5aaaf710d5f29f7" onclick="return confirm('Remove this message?');">Remove</a>

而我想使用 jgrowl 来代替...类似于:

<a href="http://domain.net/index.php?action=deletemsg;topic=1.0;msg=1;c6c7a67=f9e1fd867513be56e5aaaf710d5f29f7" onclick="$.jGrowl('Remove this message?', { header: 'Confirmation', sticky: true });"/>Remove</a>

但是...如何使用 jgrowl 实现 true/false javascript 返回? 可以只用一行完成吗?

最好的问候! 卢西亚诺

【问题讨论】:

    标签: javascript jquery dialog confirmation jgrowl


    【解决方案1】:

    编辑以支持使用 href

    你不能那样做,因为 jGrowl 不会是模态的并且会阻止你页面的行为。

    但是,您可以在选择完成后为要执行的代码创建一个函数,然后从通知中调用它

    检查这个例子http://jsfiddle.net/rcxVG/11/

    html
    

    <body>
        <a href="javascript: startDemo(1); alert('a');">link for 1</a><br>
        <a href="javascript: startDemo(2); ">link for 2</a><br>
            Will we notify again<div id="will-notitfy-again">yes</div>
    
        <br>
        now... If you want to return then
        <a href="http://www.google.com" data-confirmed="false" onclick="return returnModal(this);">click me</a>
    </body>
    

    js

    function startDemo(id)
    {
        $.jGrowl("to do not notify again click <a href='javascript:notFor("+id+")' onclick='closeNotif(this);'>here</a>!", { sticky: true });
    }
    
    function notFor(id){
        alert("not anymore for "+id);
        $("#will-notitfy-again").html("remember, notFor was hit for"+id);
    
    }
    
    function closeNotif(panel){
        $(".jGrowl-notification").has(panel).find(".jGrowl-close").click();
    }
    var counter=0;
    var confirmedAttr="data-confirmed";
    function returnModal(field){
        var $field=$(field);
        if($field.attr(confirmedAttr)=="true"){
            location.href=$field.attr("href");
        }else{
            counter++;
            //save the element somewhere so we can use it (don't know if it has an unique-id)
            $(document).data("id"+counter,$field);
            $.jGrowl("click <a href='javascript:confirmClick("+counter+")' onclick='closeNotif(this);'>here</a> to go to google!", { sticky: true });
            return false;
        }
    }
    function confirmClick(variableId){
        var $field=$(document).data("id"+variableId);
        $field.attr(confirmedAttr,"true");
        $field.click();
    }
    

    让我知道这是否足够好

    【讨论】:

      猜你喜欢
      • 2012-05-26
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2016-01-08
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多