如果为null-Jquery,则设置数组的默认值

时间:2013-07-15 07:11:12

标签: jquery

我有问题将数组中的变量设置为null。

此代码背后的想法是使用隐藏字段创建表单。如果用户选择“立即与我联系”,则会向用户显示这些字段。

我的主要问题是当字段隐藏时,默认值仍然是同步的

var $jQ = jQuery.noConflict();
$jQ(document).ready(function(){

   // some variables to track the LI and input element of the dynamic field
  var websiteRow = $jQ("#Industry,#Products__c").parents("li");
  var websiteField = $jQ("#Industry,#Products__c");

   // when the triggering field changes...
  $jQ("#Contact_Me__c").change(function() {
    var value = this.value;

     // when "Yes", show the dynamic field and make it required
     // when "No", hide the dynamic field
    switch(value)
    {
      case "Yes":
         websiteField.addClass("mktFReq");
         websiteRow.addClass("mktFormReq").slideDown();
         break;

  default:
     websiteRow.removeClass("mktFormReq").slideUp();
     websiteField.removeClass("mktFReq");
    }
  }).change();

});

0 个答案:

没有答案