简体   繁体   English

.click()函数中的jquery.confirm

[英]jquery.confirm in .click() function

I'm using a nice library named jquery.confirm and I have problem when I want to use its .confirm() method in the jQuery .click() function. 我正在使用一个名为jquery.confirm的不错的库,当我想在jQuery .click()函数中使用其.confirm()方法时遇到问题。

Here is my code: 这是我的代码:

$('#car-url').click(function()
{
    var empty = true;
    $(".departurePlace input, .arrivalPlace input, .cost input").each(function()
    {
        var input = $(this);
        if (input.val() != '' || input.val() != 0)
            empty = false;
    });
    if (empty == false)
        $(".confirm").confirm();
});

As you can see I just want to check the inputs before eventually show the dialog box. 如您所见,我只想在最终显示对话框之前检查输入。

I first contacted the developer because I thought that was a bug, but according to him it is not. 我首先与开发人员联系是因为我认为这是一个错误,但根据他的说法不是。

Any ideas? 有任何想法吗?

Edit: It can not be my selectors because when I try this: 编辑:它不能是我的选择器,因为当我尝试这样做:

$('#car-url').click(function()
{
    var empty;
    $(".departurePlace input, .arrivalPlace input, .cost input").each(function(){
    var input = $(this);
    if (input.val() != '' || input.val() != 0)
    {
        alert('test');
    }
});

I have the alert box as desired when one input is not empty. 当一个输入不为空时,我可以根据需要设置警报框。

I don't think your issue has anything to do with the confirm plugin. 我认为您的问题与确认插件无关。 As Raibaz suggested , it's your selectors. 正如Raibaz建议的那样 ,它是您的选择器。

Change your ids from my input1 to my-input1 . 将您的ID从my input1更改为my-input1

A couple fiddles to illustrate: 几个小提琴来说明:

Fiddle: selectors with spaces (based on your original code) 小提琴:带空格的选择器 (根据原始代码)

Fiddle: selectors without spaces 小提琴:没有空格的选择器

$('#my-url').click(function() {
    var empty = true;

    $("#my-input1, #my-input2").each(function() {
        if ($(this).val()) {
            empty = false;
            return false;
        }
    });

    if (! empty) {
        confirm('confirmed');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM