无刷新实时提示消息列子(类似QQ右下角的消息显示)
本人今天闲来没事,写了下这个功能!直接拷贝进去就能用!不懂的私信我!也可以问我要QQ咨询!废话不多说,下面看代码!
CSS样式添加:
<style>
body
{
margin: 0;
padding: 0 10px 0 10px;
height: 100%;
overflow: auto;
background: white;
font-size: 12px;
}
#wrap
{
display: block;
bottom: 0px;
right: 1px !important;
right: 18px;
width: 200px;
line-height: 30px;
position: fixed;
border: 1px solid #fff;
text-align: center;
color: white;
background: green;
}
*html
{
overflow-x: auto;
overflow-y: auto;
}
* html #wrap
{
position: absolute;
}
</style>
网页代码添加:
<div id="wrap" style="display: none">
<a onclick="closediv()" href="#" style="color:White " >关闭</a><br />
<label id="message">
</label>
</div>
<script type="text/javascript">
//关闭提示消息
function closediv() {
$("#wrap").fadeOut(1000);
}
function show() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "text",
url: "Table.aspx/GetMessage", //传入后台的地址/方法
data: null, //参数,这里是一个json语句
success: function (result) {
if (result.toString() == "") {
}
else {
$("#wrap").fadeIn(1000);
var myObject = eval('(' + result + ')');
document.getElementById("message").innerHTML = myObject.d;
}
}
});
}
//定时器,自己可以设定多少时间执行一次
setInterval(show, 8000);
</script>
后台代码添加:
[WebMethod]
public static string GetMessage()
{
return "您有新消息,请注意查收!";
}
后台方法自己写!