2012-06-06 25 views
2

我有此脚本并发出警报消息。我想要的只是将警报消息放在表单内的div中。这里是脚本,你可以请尽快帮助如何在窗体内部的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> 

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

+1

您无法重新定位本机'alert()'窗口。您将不得不为此创建自己的用户界面。 – 19greg96

回答

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; 
+4

哦,不!不要覆盖窗口属性! – gdoron

+0

@gdoron - 这是一个危险的解决方案,但要满足它的工作要求,只有当这是唯一显示警报的地方。但是,这是一个创造性的解决方案。 –

+0

@JamesBlack。是的,它的创意很好,但风险很大,不应该这样做。 – gdoron

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

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

您也可以缓存的div元素。