隐藏字段的Javascript值

隐藏字段的Javascript值,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有一个函数,可以设置更改为隐藏字段的日期。我当前正在从服务器接收并填充带有日期的字段。当我提交没有更改的字段时,它返回为空字符串,即使它最初显示的是日期。如果未进行任何更改,如何确保显示的日期保存回服务器 $(":asp(LeadEffectiveDate)").change(function () { var effectiveDate = $(":asp(LeadEffectiveDate)").val(); $(":asp(LeadEffectiveDateToSetFo

我有一个函数,可以设置更改为隐藏字段的日期。我当前正在从服务器接收并填充带有日期的字段。当我提交没有更改的字段时,它返回为空字符串,即使它最初显示的是日期。如果未进行任何更改,如何确保显示的日期保存回服务器

$(":asp(LeadEffectiveDate)").change(function () {
    var effectiveDate = $(":asp(LeadEffectiveDate)").val();
    $(":asp(LeadEffectiveDateToSetForUserRole)").val(effectiveDate);
});

在document ready事件中阅读它。当下拉列表更改时更新它

$(function(){

  var effectiveDate = $(":asp(LeadEffectiveDate)").val();
  $(":asp(LeadEffectiveDateToSetForUserRole)").val(effectiveDate);

  $(":asp(LeadEffectiveDate)").change(function () {

     effectiveDate = $(":asp(LeadEffectiveDate)").val();
     $(":asp(LeadEffectiveDateToSetForUserRole)").val(effectiveDate);

  });

});

另一方面,我个人更喜欢使用Id属性(
$(“#SomeUniqueId”)
)来使用jQuery选择器。

如果您的日期已经在页面加载函数中填充,请添加 在那里

$(":asp(LeadEffectiveDateToSetForUserRole)").val(effectiveDate)

我试试看。非常感谢!