2

我有这个脚本,它会发出一条警报消息。我想要的只是将警报消息放在表单内的 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>

我有一个表格。我只希望警报消息出现在顶部的表单中。我只是不知道如何在表单中显示警报消息而不是弹出窗口。

4

2 回答 2

2
function customAlert(message){
    $('#divId').html(message);
}

..
..
customAlert('Danger! aliens attacking us!')

您还可以缓存 div 元素。

于 2012-06-06T16:41:30.837 回答
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;
于 2012-06-06T16:39:49.863 回答