English 中文(简体)
我怎么能够检查一下,我干tag的田地是否无效,如果其无效与格凯有关的话。
原标题:How can I check if my div tags fields are null or not and if its null do something with Jquery

I have 5 div tags with the same class. Each div tag has a textbox and a dropdownlist with numbers.

如果所有这些<代码>div,标签箱和落户名单都是空的,如果是“做些什么”,我怎么可以检查。

$step is an array with all of my div tags.

var $step = $(".wizard-step2:visible");

我的文箱有一门<条码>Comment,我的博士生有一门<条码>。 Grade。

迄今为止,我已经把这个问题编成法典,但错了,我不想在每一张<条码>div标签上进行检查,我希望检查所有这些编号。

这部法律是错误的:

var Comment = $step.find(".Comment").val();
var Grade = $step.find(".Grade").val();

for (var i = 0; i < $step.length; i++) {
    if (Comment != null && Grade > 0) { {
        // do this
    }
    } else {
        alert("You must enter both fields");
    }
}

EDIT:

I think that I did not explain my question well, my code works like all of the answers I got on this question. I dont want to make this if statement to check each div tag. I want to be able to check if all of the div tags have any empty fields do something " else if all the div tags fields are filled do something.

Users are allowed to leave the fields empty, but if all of the div tags fields are filled do something.

I do not want to do a if statement for each div tag, I want to do a if statement if all the div tags have any empty fields or if all are field.

请允许我说,我有5个tag子。 我已经填满了其中4个,当我填满了最后5个小批。 在此,我希望“做些什么”,否则就不应该发生。 我原想的是,如果在填满的第1号、第2号、第3号、第4号等地上填写声明,如果在第5号填满时作出声明,那么所有四级标的填满,就不必做任何事情。

最佳回答

2. 选择每一类的填充成分,并使用由此产生的甄选时间进行测试:

var $step = $(".wizard-step2:visible");

// returns true if the element s value is not null
function filled() {
    return !!this.value;
}

// count the number of non-empty elements
var n_step     = $step.length; 
var n_comments = $step.find( .Comment ).filter(filled).length;
var n_grades   = $step.find( .Grade   ).filter(filled).length;

if (n_comments === n_step && n_grades === n_step) {
     // all filled
} else if (n_comments === 0 && n_grades === 0) {
     // all empty
} else {
     // mixed - do nothing
}
问题回答

与此类似:

$(".wizard-step2:visible").each(function(){
    var Comment = $(this).find(".Comment").val();
    var Grade = $(this).find(".Grade").val();

    if (Comment !=    && Grade > 0) {
    {
        // do this
    } else {
        alert("You must enter both fields");
    }
});

您可以借助这样的收集或阵列:

$(".wizard-step2:visible").each(function(count){
    var isCommentEmpty = $(this).find(".comment").val().length == 0;
    if(isCommentEmpty){
        alert( Comment on div   + count +   is empty! ;
    }
});

试图在每一件事情中听取你们的意见

    var bOK, Comment, Grade ;
        $step.each(function(){
        Comment = $(this).find(".Comment").val();
        Grade = $(this).find(".Grade").val();
if(put your condition here)
else {
bOK = false;
return false
}
        });
// Now test your condition with bOK

您应使用jQuery each(>),在$(>wizard-pan2:visible” range of divs.

查阅http://jsfiddle.net/95377/1/“rel=”nofollow>jsFiddle i 为显示你如何能够实现这一目标而创建的场所

http://www.un.org。

这里是jsFiddle代码的 j子: ——

$( .wizard-step2:visible ).each(function(){

    var txtBox = $(this).find( .comment );
    var Select = $(this).find( .Grade );
    var thisDiv = $(this).attr( id );

    if(txtBox.val().length > 0 && Select.val().length > 0)
    {
        alert("values for " +thisDiv+ " are fine");
    }
    else
    {
        alert("please fill in both values for " + thisDiv);
    } 
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签