jQuery:如果ul为空 [英] jquery: if ul is empty

查看:85
本文介绍了jQuery:如果ul为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个jQuery对话框,其中包含一个表单,我不知所措,试图弄清楚这一点...让我们看看我是否可以口头表达我要做的事情.

Okay I have a jQuery dialog box which has a form in it and I am at my wits end trying to figure this out... Lets see if I can verbalize what I am trying to do..

我有3个文本框. #apInterest#apPayment#apPrincipal的确切顺序.

I have 3 text boxes. #apInterest, #apPayment and #apPrincipal in that exact order.

我要做什么的基本英语术语:

basic english terms of what i am trying to do:

在keyup上触发错误..否则检查ul#mylist是否具有任何li,如果没有.hide

on keyup in #apInterest if .val is less than 0 or greater than 99.99 trigger an error.. else check ul#mylist if it has any li, if not .hide

触发错误,否则请检查li隐藏的列表.

on keyup in #apPayment if .val is less than 0 trigger an error else check the list for li hide if not.

#apPrincipal#apPayment

我现在正确的是什么

$('#apInterest').live("keyup", function(e) {
var parent = $('.inter').parents("ul:first");
if ($('#apInterest').val() < 0 || $('#apInterest').val() > 99.99) {
    $('.inter').remove();
    $('#mylist').append('<li class="inter">Interest Rate cannot be below 0 or above 99.99</li>');
    $('#popuperrors').show();
    $(this).addClass('error');
} else {
    $(this).removeClass('error');
    $('.inter').remove();
    alert(parent.children().text);
    if (parent.children().length == 0){
        $('#popuperrors').hide();
    }
}
});

尽管我也尝试过

if ($("#mylist :not(:contains(li))") ){
$('#popuperrors').hide();
}

对于所有3个文本框,我都具有与此功能相似的功能,但我尝试过的所有功能似乎均无效..关于如何完成此操作的任何想法

I had a function similar to this for all 3 textboxes but none of what I have tried seems to work.. any ideas on how to complete this

推荐答案

if ($('#mylist li').length == 0) ...

这篇关于jQuery:如果ul为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆