javascript - Jquery .replaceWith() 没有用更新的文本正确更新
问题描述
我有一个表单,在提交之前我正在验证它。顾名思义,根据用户选择ValidateForm()
验证表单并验证表单上的一组字段。ValidateRange(num)
从我这里得到验证正在正确完成。
if
在我检查结果的最后一个语句中,如果我使用 jQuery .append()
,它工作正常,但我想用replaceWith()
方法替换验证文本,但它没有发生。
result.message
只是一个文本字符串,说明哪个字段存在验证问题并将用户指向它。
在console.log()
我可以看到验证指针消息正确出现,因为我用正确的值修复了字段,但由于某种原因,它<div id ='ValidationDiv'></div>
一次又一次地用第一个指针消息替换。
function ValidateForm() {
var result = {valid:true, message:"In-Progress"};
if ($('#firstRangeRadioButton').is(':checked'))
result = ValidateRange(1);
else if ($('#secondRangeRadioButton').is(':checked'))
{
result = ValidateRange(1);
if(result.valid == true)
result = ValidateRange(2);
}
else if ($('#thirdRangeRadioButton').is(':checked')) {
result = ValidateRange(1);
if (result.valid == true)
result = ValidateRange(2);
if (result.valid == true)
result = ValidateRange(3);
}
if (result.valid == false)
{
console.log(result.message);
message = "<div class=\"well well-sm\"><div><div class=\"blink\"><strong>Validation Failed: </strong>" + result.message + "</div></div></div>";
$('#ValidationDiv').replaceWith(message);
blink('.blink');
console.log(message);
return false;
}
else
return true;
}
解决方案
推荐阅读
- node.js - 在 Nginx 中使用查询参数启用 React/Express Route
- kubernetes - 如何访问另一个 pod(busybox)中的 mysql pod?
- powershell - 通过 PowerShell 访问 MS Graph API 的权限
- sharepoint - 将 Microsoft Clarity 与 SharePoint 集成
- jquery - 使用唯一 ID 的 Chrome 存储集
- java - 如何在 Selenium 的 soft assertAll() 中仅打印失败的断言而没有堆栈跟踪?
- android - 为什么这里用红色突出显示 -
- amazon-cognito - 当每秒请求超过一定限制时,我们如何获得警告。(Cognito AWS 的配额)
- python - 如何用新列表永久替换列表?
- bash - 在bash中获取最后执行的命令