2012-02-18 63 views
0

我想在if block in jquery里面显示一个错误警告框,但是错误即将到来。任何人都可以帮助我。我找到了this website的警报框,但是在这种情况下,我必须点击错误消息弹出警报来查看警报,但是如何在我的jquery if part内添加错误消息弹出警报警报,以便不点击该警报框就会显示警报?在jQuery里面的css警报框

$("#textbox").keyup(function() { 
    $.getJSON('check.jsp', { 
     textboxname: this.value 
    },function(data){ 
     if(data.isTrue){ 
      $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert 
     } 
     else{ 
     //do something 
     }    
    }); 
}); 
+0

你可以做到这一点的,如果块什么是你所得到的误差内 – Rafay 2012-02-18 10:18:50

+0

实际上没有警告框出现您是否看到该网站我必须单击错误消息弹出警报警报以显示警报,但没有任何点击它不出现 – Phillipa 2012-02-18 10:21:01

+0

@ 3nigma任何建议请 – Phillipa 2012-02-18 10:30:22

回答

1

这样称呼它下面的代码,

$("#textbox").keyup(function() { 
    $.getJSON('check.jsp', { 
     textboxname: this.value 
    },function(data){ 
     if(data.isTrue){ 
      $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert 
      csscody.alert(data); 
     } 
     else{ 
     //do something 
     }    
    }); 
}); 
+0

谢谢你的答案,但你可以请添加错误来自[this](http://csscody.com/demo/wp-content/demo/popup/demo.htm)网站的消息弹出警报(位于第二位)? – Phillipa 2012-02-18 10:29:02

+0

'csscody.error('error text');' – 2012-02-18 10:31:08

+0

好的,但是这是什么csscody?我必须在该函数中编写css编码? – Phillipa 2012-02-18 10:37:31

1
if(data.isTrue){ 
    $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert 
    csscody.alert('<h1>Hello World</h1>'); 
    return false; 

} 
0

包括在HEAD节以下js文件

http://csscody.com/demo/wp-content/demo/popup/js/jquery.easing.1.3.js

http://csscody.com/demo/wp-content/demo/popup/js/alertbox.js

http://csscody.com/demo/wp-content/demo/popup/js/style.css

然后在if块内的成功处理程序提醒消息像

$("#textbox").keyup(function() { 
    $.getJSON('check.jsp', { 
     textboxname: this.value 
    },function(data){ 
     if(data.isTrue){ 
      csscody.alert("user name already exists"); 
      $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert 

     } 
     else{ 
     //do something 
     }    
    }); 
}); 

DEMO

+0

雅我包括在头部分的所有文件,但它仍然没有像那样的警报工作。 – Phillipa 2012-02-18 10:55:21

+0

在你的演示中它工作正常,但在你的上述代码中我找不到任何成功处理程序 – Phillipa 2012-02-18 10:58:09

+0

AH!你作为getJSON函数的第二个参数传递的函数被称为成功处理程序 – Rafay 2012-02-18 11:13:30