2011-05-26 46 views
2

我有一組通過環路產生的表單字段的:警告如果至少一個值不是空

foreach ($arrays as $listValue) { 
    echo ' 
    <div> 
     <input type="text" maxlength="100" name="field[]"> 
    </div>'; 
} 
<a href="#" id="myLink">link</a> 

我也有以下鏈接,即點擊時調用一個jQuery功能。

如果點擊我的鏈接時,如果表單域中至少有一個值存在,我想添加一個檢查並顯示警告(警告很好)。

回答

2
$(':input').each(function(){ 
    if($(this).val() != '') 
    { 
     alert('warning'); 
    } 
}) 
5
if($('input[value!=""]').length > 0) { 
    //at least one field is filled out 
} 
+0

不錯!我正在考慮在創建時序列化整個表單,並將其與當前的序列化值進行比較,但這非常簡單。 – 2011-05-26 18:25:07

+0

請注意,它會將單個空間視爲填充該字段,這可能不是您想要的,具體取決於實施。 – DarthJDG 2011-05-26 18:36:13

+0

@DarthJDG真的......有沒有解決這個問題的方法? – santa 2011-05-26 18:49:49

相關問題