How to check 'undefined' value in jQuery

后端 未结 11 570
慢半拍i
慢半拍i 2020-12-12 11:49

Possible Duplicate:
Detecting an undefined object property in JavaScript
javascript undefined compare

H

11条回答
  •  -上瘾入骨i
    2020-12-12 12:07

    If you have names of the element and not id we can achieve the undefined check on all text elements (for example) as below and fill them with a default value say 0.0:

    var aFieldsCannotBeNull=['ast_chkacc_bwr','ast_savacc_bwr'];
     jQuery.each(aFieldsCannotBeNull,function(nShowIndex,sShowKey) {
       var $_oField = jQuery("input[name='"+sShowKey+"']");
       if($_oField.val().trim().length === 0){
           $_oField.val('0.0')
        }
      })
    

提交回复
热议问题