【问题标题】:Jquery raty is theres a way to callback the cancel button?Jquery 有没有办法回调取消按钮?
【发布时间】:2015-09-14 22:52:34
【问题描述】:

这里有谁熟悉 jquery 比率吗?

有没有办法回调取消按钮?

这是我的代码

$(".ratings").raty({
    cancel: function() {
        return $(this).attr("data-cancel");
    }
}); 

我想要这样的东西。但我的代码似乎不起作用。

【问题讨论】:

    标签: jquery rating-system raty


    【解决方案1】:

    尝试使用下面我的示例中的代码。您会看到 click 事件的回调函数。因为它会在所有点击时执行,所以你必须找到一种方法,只在点击取消按钮时执行一些代码。在我的示例中,您会看到此检查是根据单击元素的类名完成的。

    $(".ratings").raty({
        cancel : true,
        click  : function(score, evt) {
            alert("Score: " + score);
    
            // This is one way to check if you clicked the cancel button.
            if(evt.currentTarget.className === "raty-cancel")
            {
                // At this point we know you clicked the cancel button,
                // so insert code here to execute on callback.
            }
        }
    });
    

    在回调函数中alert("Score: " + score);返回null,所以当它到达这个方法时,由于点击取消按钮,分数已经被删除了。

    【讨论】:

    • 谢谢您,先生,但我想要做的是不显示取消按钮,除非我将 data-cancel="true" 放在我的 html 标记中,它将取消回调为 true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多