我有这个脚本并发出警告信息。我想要的是将警报消息放在表单内的div中。这是脚本,你可以请尽快帮助
<script type="text/javascript">
var registered=false
function ExamineRegistration()
{
var email =document.regform.email.value;
var emailcheck= email.indexOf("@")
var emailcheck2= email.indexOf(".")
var password = document.regform.pass.value;
var passcheck = password.charAt(0)
var message_out = "Errors: "
if(email=="" || password==""){
message_out = message_out+"All boxes should be filled in, "
}
if(emailcheck==-1 || emailcheck2==-1)
{
message_out = message_out+"email must contain @ and ., "
}
if(password!=password)
{
message_out=message_out+"password must match"
}
if(message_out == "Errors: ") {
message_out = "You have successfully been logged in!"
registered=true
}
alert(message_out);
}
--> This function helps the user first to register and than to enter the site.
function Checkreg() {
if (registered ==true) {
location.replace("http://www.google.com")
}
else alert("Please Login to proceed")
}
</script>
我有一张表格。我只是希望警告消息显示在顶部的表单中。我只是不知道如何在表单中显示警告消息而不是弹出窗口。
答案 0 :(得分:2)
function customAlert(message){
$('#divId').html(message);
}
..
..
customAlert('Danger! aliens attacking us!')
您也可以缓存div元素。
答案 1 :(得分:1)
window.realAlert = window.alert;
window.alert = function(msg) {document.getElementById('my_div_id').innerHTML = msg;}
.... some code with redirected alerts ....
// restoring alert
window.alert = window.realAlert;