English 中文(简体)
检查所有*田是否具有价值
原标题:Use jquery to check if *any* fields have a value?

从这样的一开始:

    $( #report-form ).submit( function(){
    if ( ! $( #datetime, :checkbox, :radio, textarea ).val() ){
            alert( not posted );
            return false;
        } else  {
            alert( posted );
        }

} );

除不把任何领域都空出外,我要求将其张贴在所列领域/外地类型中<>all为空洞<>。 是否有办法通过挑选人员加以说明,而不是手工检查每一个项目?

我认为可以发挥一种作用,即当它空洞时,就会出现一个变数,而且只有在其数量少于田地数时,才提交,但理想的做法是,我只想看一个更通用的东西(即用检查箱和无线电塔顿以及文字投入和文字领域开展工作)。

问题回答

您可使用<代码>$.grep,以收回符合条件的内容。

如果有任何要素具有价值,它将从背书中退回<代码>true,而length至少将是1, coercing to true

var any = !!$.grep($( #datetime, :checkbox, :radio, textarea ), function(el) { 
    return !!el.value;
}).length;

if (any) {
    // there was at least one
}

另一种可能性是利用attribute-not-qualitys-selector,尽管我建议这样做。

if (!!$( input[value!=""] ).length)

它要求核对属性,但似乎实际检查了<代码>。 对我来说,这似乎很有说服力。 既然对属性进行核查,我很可能避免。

你们可以通过你们想要的所有投入和文本处理,并为<条码><>真实性/代码>设定一个变量。 (最初定在<代码>false上)上,如果收到并非空洞的投入,则停泊。 然后,你只检查变数是否真实,或者是否在休息之后。

You can use the method valid() to invoke the validator directly.

$("#myform").validate();
$("a.check").click(function() {
    alert("Valid: " + $("#myform").valid());
    return false;
});




相关问题
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.