1
我有一些代码来设置隐藏字段的值,所以我可以在后面的代码中访问它,但在后面的代码中该值始终为空。 effectiveDate
的值正在设置,但我看起来没有设置隐藏字段属性Value
。使用jquery设置隐藏字段的问题使用jquery
<input id="appEffectiveDate" type="text" />
<label id="effectiveDateLabel" for="appEffectiveDate">App Effective Date</label>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<asp:HiddenField ID="appEffectiveDateToSetForUserRole" runat="server" Value="" Visible="false" />
<script>
$(function() {
var SelectedDates = {};
$('#appEffectiveDate').datepicker({
beforeShowDay: function (date) {
var Highlight = SelectedDates[date];
if (Highlight) {
return [true, "Highlighted", Highlight];
}
else {
return [true, '', ''];
}
}
});
$("#effectiveDateLabel").hide();
$("#appEffectiveDate").hide();
$('input[value="85"]').click(function() {
if($(this).is(':checked'))
{
$("#effectiveDateLabel").show();
$("#appEffectiveDate").show();
}
});
$("#appEffectiveDate").change(function() {
var effectiveDate = $("#appEffectiveDate").val();
$(":asp(appEffectiveDateToSetForUserRole)").prop('value', effectiveDate);
});
});
</script>
在值后面的代码隐藏字段为空:
if (!string.IsNullOrEmpty(appEffectiveDateToSetForUserRole.Value))
{
// this is never called because .Value is empty
}