国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net利用JQuery彈出層加載數(shù)據(jù)代碼

2024-07-10 13:19:14
字體:
供稿:網(wǎng)友
首先我們新建一個網(wǎng)站,在網(wǎng)站里面新增一般處理程序,命名為ReadData.ashx。然后在里面輸入如下代碼:

復(fù)制代碼 代碼如下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient; //引入命名空間
using System.Data;

namespace 加載層
{
/// <summary>
/// $codebehindclassname$ 的摘要說明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ReadData : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");

//獲取外部傳進(jìn)來的變量值i
int i = Int32.Parse(context.Request.QueryString["i"]);

//連接數(shù)據(jù)庫

SqlConnection con = new SqlConnection("data source=.;user id=sa;pwd=5239898;database=librarydatabase;");
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from reader where 序號='" + i + "'", con);
SqlCommandBuilder com = new SqlCommandBuilder(ada);
DataSet ds = new DataSet();
ada.Fill(ds, "reader");

con.Close();

//讀取表中欄位為“姓名”的字段值,并傳出

context.Response.Write(ds.Tables["reader"].Rows[0]["姓名"].ToString());


}

public bool IsReusable
{
get
{
return false;
}
}
}
}


然后我們需要新建一個JavaScript文件,命名為loaddata.js。輸入如下代碼:

復(fù)制代碼 代碼如下:



/*當(dāng)DOM加載完畢之后就自動為兩個鏈接添加Click事件*/
$("document").ready(function() {
$("a[href=javascript]").click(function() {
chkform();
return false;
})
$("a[href=test]").click(function() {
$("#load").css("display", "none");
$("#mark").css("display", "none");
return false;
})
});


var chkform = function() {
new Request({

/*調(diào)用一般處理程序進(jìn)行后臺抓取數(shù)據(jù)并返回txt變量*/
url: 'ReadData.ashx?i=' + $("#Text1").attr("value"),

/*抓取數(shù)據(jù)成功之后*/
onSuccess: function(txt) {
$("#load").append("<P>" + txt + "</P>");

$("#load").css("display", "block");
$("#mark").css("display", "block");
},

/*正在抓取*/
onRequest: function() {

$("#load").append("<P>正在加載</P>");
},

/*數(shù)據(jù)加載失敗*/
onFailure: function() {
alert('信息加載失敗!');

}
}).send();
}


還沒完,我們還要新增一個CSS文件,命名為main.css,深入如下樣式:

復(fù)制代碼 代碼如下:


#mark{
width: 100%;
background-color:White;
position:absolute;
left: 0px;
top: 0px;
height: 700px;
filter:alpha(opacity=70);
-moz-opacity:70;
opacity:70;
z-index:2;
display:none;
}
#load
{
background-color:Gray;
border: 1px solid #999;
font-size: 12px;
position:relative;
margin:0 auto;
margin-top:100px;
width:200px;
height:150px;
z-index:99;
display:none;
}




我們在網(wǎng)站的首頁里面源碼輸入如下代碼:

復(fù)制代碼 代碼如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="加載層._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>加載層</title>
<link type="text/css" href="main.css" />

<script type="text/javascript" src="mootools.js"></script> //記得引入這個javascript庫文件

<script type="text/javascript" src="jquery-1.3.1-vsdoc.js"></script> //VS支持智能提示的文件,可有可無

<script type="text/javascript" src="jquery-1.3.1.js"></script> //記得引入JQuery

<script type="text/javascript" src="loaddata.js"></script>

</head>
<body>
<div>
<a href="javascript">點擊加載</a>
<input type="text" /></div>
<div>
load <a href="test">試試</a>
</div>
<div>
</div>
</body>
</html>


至此完成了我們要的效果。
效果圖及DEMO一會放出。

Asp.net利用JQuery彈出層加載數(shù)據(jù)代碼


看上面的鏈接以及文本框都處于“灰色”狀態(tài),不可編輯。點擊中間彈出層的鏈接可以回到最初狀態(tài)。整個過程中頁面都沒有刷新!

Demo下載地址:
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 浦东新区| 永仁县| 高雄县| 镶黄旗| 阿尔山市| 老河口市| 金华市| 黎川县| 顺昌县| 宿州市| 美姑县| 青阳县| 濮阳市| 西藏| 常宁市| 东至县| 苏尼特右旗| 汤阴县| 武宣县| 响水县| 大余县| 镇巴县| 松阳县| 渭南市| 商河县| 上林县| 格尔木市| 乌拉特前旗| 昂仁县| 东丽区| 靖江市| 滕州市| 阳春市| 文化| 交城县| 迁安市| 陆丰市| 遂宁市| 台东市| 库尔勒市| 濉溪县|