【发布时间】:2018-01-27 02:52:56
【问题描述】:
我有一个带有以下错误消息的表单。此错误消息正常运行,所以我先分享它,然后显示我接下来要更改的内容:
if (thing is true) {
$(this).parents("table:first")
.prop("disabled",true)
.css({'background-color' : 'lightgray'})
.after("<font color = red id=error3><strong>*</strong> Please check that your start and end dates are between June 15, 2018 and November 30, 2019. The Start Date may not be greater than the End Date.</font>");
}
我想更改错误消息以在表单中包含用户较早的日期提供程序。当我使用连接时,它看起来像这样:
if (thing is true) {
// example dates provided by user
cysd = $("#id_currentyearstartdate").val();
cyed = $("#id_currentyearenddate").val();
// let's say cysd is January 1, 2018 and cyed is December 31, 2018
$("input#next-submit-button")
.prop("disabled",true)
.css({'background-color' : 'lightgray'})
.after("<font color = red id=error2><br>Please resolve any errors above before continuing. <br><strong>*</strong> Check that your start and end dates are between </font>" + cysd + "<font color = red id=error2> and </font>" + cyed + "<font color = red id=error2>. The Start Date may not be greater than the End Date.</font>");
我搞砸的地方是,在原始错误消息中,我有一条错误消息,字体 ID 为“error2”。这使我能够在正确的条件下轻松添加或删除错误消息。
我不知道如何在实际的错误消息文本或字体标记中包含变量值,这样当 id=error2 时仍会引用 整个 string "请检查您的开始日期和结束日期是否在 2018 年 1 月 1 日至 2018 年 12 月 31 日之间。开始日期不得早于结束日期。
【问题讨论】:
-
<font>标签已弃用。应该改用css
标签: javascript jquery html css