如何使用 "name = xxx" 进行验证
How to do Validation using "name = xxx"
如何使用“名称”进行验证
这是贷款自动计算脚本。
https://jsfiddle.net/diessses/Lpaqnoue/
我对验证有疑问。
我可以使用“id = xxx”进行错误检查。但我将代码更改为“name = xxx”。
你能教我如何使用“name = xxx”编写代码吗?
function showError(error) {
document.getElementById('results').style.display = 'none';
document.getElementById('loading').style.display = 'none';
const errorDiv = document.createElement('div');
const card = document.querySelector('.card');
const heading = document.querySelector('.heading');
errorDiv.className = 'alert alert-danger';
card.insertBefore(errorDiv, heading);
setTimeout(clearError, 300);
}
而且我想在“cb_amount”输入字段进行验证。
'cb_amount' 值必须这样
'cb_amount' =< ('amount' - 'downpayment') / 2
我想在 showError 函数中添加这个。
使用 getElementsByName 获取元素。
let downpayment = documnet.getElementsByName("downpayment")[0].value
let amount = document.getElementsByName("amount")[0].value
let cb_amount = document.getElementsByName("cb_amount")[0].value
现在你可以写下你的条件了。
这里 documnet.getElementsByName("downpayment") 返回的值是类似元素的数组,因此我们需要使用 [0] 来获取所需的元素。
如何使用“名称”进行验证
这是贷款自动计算脚本。
https://jsfiddle.net/diessses/Lpaqnoue/
我对验证有疑问。 我可以使用“id = xxx”进行错误检查。但我将代码更改为“name = xxx”。 你能教我如何使用“name = xxx”编写代码吗?
function showError(error) {
document.getElementById('results').style.display = 'none';
document.getElementById('loading').style.display = 'none';
const errorDiv = document.createElement('div');
const card = document.querySelector('.card');
const heading = document.querySelector('.heading');
errorDiv.className = 'alert alert-danger';
card.insertBefore(errorDiv, heading);
setTimeout(clearError, 300);
}
而且我想在“cb_amount”输入字段进行验证。
'cb_amount' 值必须这样
'cb_amount' =< ('amount' - 'downpayment') / 2
我想在 showError 函数中添加这个。
使用 getElementsByName 获取元素。
let downpayment = documnet.getElementsByName("downpayment")[0].value
let amount = document.getElementsByName("amount")[0].value
let cb_amount = document.getElementsByName("cb_amount")[0].value
现在你可以写下你的条件了。 这里 documnet.getElementsByName("downpayment") 返回的值是类似元素的数组,因此我们需要使用 [0] 来获取所需的元素。