我的Javascript表单验证存在问题,我正在尝试返回它是否为真,值是否正在工作。它只返回第一个if / else语句(无论是true还是false)和从那里它不起作用。一旦你看到JavaScript,你应该能够理解我想要做的。
var downloadTask: URLSessionDownloadTask?
var session: URLSession?
override func viewDidLoad() {
super.viewDidLoad()
let configuration = URLSessionConfiguration.background(withIdentifier: "backgroundSession")
session = URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue.main)
let url = URL(string: "https://unsplash.it/200/300/?random")!
downloadTask = session?.downloadTask(with: url)
downloadTask!.resume()
}
答案 0 :(得分:0)
返回将突破该功能。相反,设置一个标志并在结尾返回该标志。
$('#button').click(function(){
returnFlag = false
name = $("#name").val(); //name input
age = $("#age").val(); //age input
sex = $("#sex").val(); // sex input
if(name.match(/(\w)\s(\w)/)){
returnFlag = true;
}
else {
$('.form-row:first-child').css('border','1px solid red');
returnFlag = false;
}
if (age < 0 || age > 130 || isNaN(age)) {
$('.form-row:nth-child(2)').css('border','1px solid red');
returnFlag = false;
}
else {
returnFlag = true;
}
if (sex == "male" || sex == "Male" || sex == "female" || sex == "Female"){
returnFlag = true;
}
else {
$('.form-row:nth-child(3)').css('border','1px solid red');
returnFlag = false;
}
return returnFlag;
});
&#13;