一个非常奇怪的问题。我在表单上提供了一些应该自动填充某些字段(文本框)的按钮。应该插入文本框的值是要评估的javascript函数。但即使我只是尝试将纯文本放在那里,他们也不会更新。
设置这些值的按钮似乎正确设置文本框上的值,因为我有另一个评估值的按钮。但是文本框在屏幕上仍然是空的,当用F12工具查看标记时,我什么也看不见。
我提前为糟糕的格式化道歉。我只是想使用JFiddle链接来简化和甜蜜,但Stackoverflow不会让我。精氨酸。
https://jsfiddle.net/ox5cat40/
<div class="container-row">
<div id="DateValidationPanel"></div>
<div id="StartEndDateButtons" class="container-row">
<button id="ScheduleTodayButton">Today</button>
<button id="ScheduleLast24Button">Last 24 Hours</button>
<button id="ScheduleLastWeekButton">Last Week</button>
<button id="ScheduleCurrentMonthButton">Current Month</button>
<button id="EvaluateButton">Verify Start & End Dates</button>
</div>
<table id="ScheduleParametersTable">
<thead>
<tr>
<th class="schedule-td-1">Parameter</th>
<th class="schedule-td-2">Type</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Parameters_0__Id" name="Parameters[0].Id" type="hidden" value="0">
<input id="Parameters_0__Name" name="Parameters[0].Name" type="hidden" value="PSTART_DATE">
<input id="Parameters_0__DisplayText" name="Parameters[0].DisplayText" type="hidden" value="Start Date">
<input data-val="true" data-val-number="The field ParameterId must be a number." data-val-required="The ParameterId field is required." id="Parameters_0__ParameterId" name="Parameters[0].ParameterId" type="hidden" value="422">
<input data-val="true" data-val-number="The field DotNetTypeId must be a number." data-val-required="The DotNetTypeId field is required." id="Parameters_0__DotNetTypeId" name="Parameters[0].DotNetTypeId" type="hidden" value="3">
<input data-val="true" data-val-number="The field CaptureTypeId must be a number." data-val-required="The CaptureTypeId field is required." id="Parameters_0__CaptureTypeId" name="Parameters[0].CaptureTypeId" type="hidden" value="3">
<input id="Parameters_0__CaptureType" name="Parameters[0].CaptureType" type="hidden" value="">
<input data-val="true" data-val-number="The field Ordering must be a number." data-val-required="The Ordering field is required." id="Parameters_0__Ordering" name="Parameters[0].Ordering" type="hidden" value="1">
<input id="Parameters_0__DropDownQueryName" name="Parameters[0].DropDownQueryName" type="hidden" value="">
<input data-val="true" data-val-number="The field DropDownQueryProjectId must be a number." id="Parameters_0__DropDownQueryProjectId" name="Parameters[0].DropDownQueryProjectId" type="hidden" value="">
<input data-val="true" data-val-number="The field DropDownQueryParam must be a number." id="Parameters_0__DropDownQueryParam" name="Parameters[0].DropDownQueryParam" type="hidden" value="">
<input id="Parameters_0__Value" name="Parameters[0].Value" type="hidden" value="((new Date()).getMonth()) + "/" + ((new Date()).getDate()) + "/" + (new Date()).getFullYear()">
<input id="Parameters_0__ScheduledValue" name="Parameters[0].ScheduledValue" type="hidden" value="var d = new Date();(d.getMonth()+1) + '/1/'+d.getFullYear();">
<input id="Parameters_0__Type" name="Parameters[0].Type" type="hidden" value="DynamicReport.Models.ReportParameter">
<input id="Parameters_0__DropDownValue" name="Parameters[0].DropDownValue" type="hidden" value="">
Start Date
</td>
<td></td>
<td>
<input id="Parameters_0__ScheduledValue" name="Parameters[0].ScheduledValue" type="text" class="scheduled-value"/> </td>
</tr>
<tr>
<td>
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Parameters_1__Id" name="Parameters[1].Id" type="hidden" value="0">
<input id="Parameters_1__Name" name="Parameters[1].Name" type="hidden" value="PEND_DATE">
<input id="Parameters_1__DisplayText" name="Parameters[1].DisplayText" type="hidden" value="End Date">
<input data-val="true" data-val-number="The field ParameterId must be a number." data-val-required="The ParameterId field is required." id="Parameters_1__ParameterId" name="Parameters[1].ParameterId" type="hidden" value="423">
<input data-val="true" data-val-number="The field DotNetTypeId must be a number." data-val-required="The DotNetTypeId field is required." id="Parameters_1__DotNetTypeId" name="Parameters[1].DotNetTypeId" type="hidden" value="3">
<input data-val="true" data-val-number="The field CaptureTypeId must be a number." data-val-required="The CaptureTypeId field is required." id="Parameters_1__CaptureTypeId" name="Parameters[1].CaptureTypeId" type="hidden" value="3">
<input id="Parameters_1__CaptureType" name="Parameters[1].CaptureType" type="hidden" value="">
<input data-val="true" data-val-number="The field Ordering must be a number." data-val-required="The Ordering field is required." id="Parameters_1__Ordering" name="Parameters[1].Ordering" type="hidden" value="2">
<input id="Parameters_1__DropDownQueryName" name="Parameters[1].DropDownQueryName" type="hidden" value="">
<input data-val="true" data-val-number="The field DropDownQueryProjectId must be a number." id="Parameters_1__DropDownQueryProjectId" name="Parameters[1].DropDownQueryProjectId" type="hidden" value="">
<input data-val="true" data-val-number="The field DropDownQueryParam must be a number." id="Parameters_1__DropDownQueryParam" name="Parameters[1].DropDownQueryParam" type="hidden" value="">
<input id="Parameters_1__Value" name="Parameters[1].Value" type="hidden" value="((new Date()).getMonth()+1) + "/" +(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0)).getDate() + "/" + (new Date()).getFullYear()">
<input id="Parameters_1__ScheduledValue" name="Parameters[1].ScheduledValue" type="hidden" value="((new Date()).getMonth()+1)+'/'+(new Date(new Date().getFullYear(),new Date().getMonth()+1,0)).getDate()+'/'+(new Date()).getFullYear();">
<input id="Parameters_1__Type" name="Parameters[1].Type" type="hidden" value="DynamicReport.Models.ReportParameter">
<input id="Parameters_1__DropDownValue" name="Parameters[1].DropDownValue" type="hidden" value="">
End Date
</td>
<td></td>
<td>
<input id="Parameters_1__ScheduledValue" name="Parameters[1].ScheduledValue" type="text" class="scheduled-value"/> </td>
</tr>
</tbody></table>
</div>
var today = "var d = new Date();(d.getMonth()+1) + '/' + d.getDate() + '/'+d.getFullYear();";
var yesterday = "var d = new Date();d.setDate(d.getDate()-1);(d.getMonth()+1) + '/' + d.getDate() + '/'+d.getFullYear();";
var sevenDaysAgo = "var d = new Date();d.setDate(d.getDate()-7);(d.getMonth()+1) + '/' + d.getDate() + '/'+d.getFullYear();";
var firstOfCurrentMonth = "var d = new Date();(d.getMonth()+1) + '/1/'+d.getFullYear();";
var lastOfCurrentMonth = "((new Date()).getMonth()+1)+'/'+(new Date(new Date().getFullYear(),new Date().getMonth()+1,0)).getDate()+'/'+(new Date()).getFullYear();";
function evalDate(dateType, input) {
var result;
try {
var dateResult = eval(input);
result = "<span class='date-valid'>" + dateType + ": " + dateResult + "</span><br/>";
} catch (ex) {
result = "<span class='date-error'>" + dateType + ": Syntax Error</span><br/>";
}
return result;
}
$("#EvaluateButton").click(function (e) {
e.preventDefault();
var result;
$("#DateValidationPanel").html("");
$("input[name$='DisplayText']").each(function () {
if ($(this).val().toLowerCase().indexOf("start") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
result = evalDate("Start Date", $("input[name$='ScheduledValue']").eq(index).val());
$("#DateValidationPanel").append(result);
}
if ($(this).val().toLowerCase().indexOf("end") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
result = evalDate("End Date", $("input[name$='ScheduledValue']").eq(index).val());
$("#DateValidationPanel").append(result);
}
});
return false;
});
$("#ScheduleTodayButton").click(function (e) {
e.preventDefault();
$("input[name$='DisplayText']").each(function () {
// Set Start Date
if ($(this).val().toLowerCase().indexOf("start") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(today);
}
// Set End Date
if ($(this).val().toLowerCase().indexOf("end") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(today);
}
});
return false;
});
$("#ScheduleLast24Button").click(function (e) {
e.preventDefault();
$("input[name$='DisplayText']").each(function () {
// Set Start Date
if ($(this).val().toLowerCase().indexOf("start") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(yesterday);
}
// Set End Date
if ($(this).val().toLowerCase().indexOf("end") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(today);
}
});
return false;
});
$("#ScheduleLastWeekButton").click(function (e) {
e.preventDefault();
$("input[name$='DisplayText']").each(function () {
// Set Start Date
if ($(this).val().toLowerCase().indexOf("start") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(sevenDaysAgo);
}
// Set End Date
if ($(this).val().toLowerCase().indexOf("end") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(today);
}
});
return false;
});
$("#ScheduleCurrentMonthButton").click(function (e) {
e.preventDefault();
$("input[name$='DisplayText']").each(function () {
// Set Start Date
if ($(this).val().toLowerCase().indexOf("start") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(firstOfCurrentMonth);
}
// Set End Date
if ($(this).val().toLowerCase().indexOf("end") >= 0) {
index = $("input[name$='DisplayText']").index($(this));
$("input[name$='ScheduledValue']").eq(index).val(lastOfCurrentMonth);
}
});
return false;
});
这里发生了什么?