function validateFirst(first)
{
if (first == "")
{
error += "\nPlease enter your name";
first.focus();
}
}
function errorMessage()
{
if (error != "")
{
alert("The following data was be entered correctly: \n " + error);
error = "";
}
else
{
document.write("Thank you for submitting your information");
}
}
我的注意力无效。我在我的js文件中有这个功能。我把它叫做我的HTML
function validateAll()
{
var first = document.form.first.value;
first = validateFirst(first);
errorMessage();
}
点击提交按钮并弹出警告框后,我需要关注第一条错误消息。
答案 0 :(得分:0)
尝试以下方法:
//change 1
function validateFirst(elem)
{
if (elem.value == "")
{
error += "\nPlease enter your name";
elem.focus();
}
}
//change 2
function validateAll()
{
var elem = document.form.first;
validateFirst(elem);
errorMessage();
}