0
任何人都可以告訴我如何將CSS文本格式添加到JavaScript推送錯誤? 例如,如果我想margin-top:10px; margin-bottom:10px;
加入如何將CSS文本格式添加到JavaScript推送錯誤?
errors.push("You did not complete Company Name");
我的JavaScript代碼:
<script>
function displayErrors(errors){
var container = document.getElementById("alertBox2");
var html = "<ul>";
for(var i=0; i<errors.length; i++){
html += "<li>" + errors[i] + "</li>";
}
html += "</ul>";
container.innerHTML = html;
container.style.display = "block";
}
function validateForm(){
var cname = document.forms["myForm"]["cname"].value;
var creg= document.forms["myForm"]["creg"].value;
var address= document.forms["myForm"]["address"].value;
var post= document.forms["myForm"]["post"].value;
var contactn= document.forms["myForm"]["contactn"].value;
var contactt= document.forms["myForm"]["contactt"].value;
var email= document.forms["myForm"]["email"].value;
var errors = [];
if(cname == ""){
document.body.scrollTop = document.documentElement.scrollTop = 0;
document.getElementById("alertBox").style.display='block';
errors.push("You did not complete Company Name");
}
if(errors.length > 0){
displayErrors(errors);
return false;
} else {
return true;
}
}
</script>
呃,這樣'HTML + = 「