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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Ajax實現(xiàn)網(wǎng)易相冊樣式的修改

2019-11-18 17:15:53
字體:
供稿:網(wǎng)友

普通的Ajax應(yīng)用,結(jié)合javascript對html元素的動態(tài)操控,結(jié)合而成一個優(yōu)美的效果。

還是用Ajax.net,設(shè)置與前篇文章一樣,不再累述。
代碼如下:
163photoTest.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _163photoTest : System.Web.UI.Page
{
    PRotected void Page_Load(object sender, EventArgs e)
    {
        description.Text  = GetDescription();
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_163photoTest));
    }

    //取數(shù)據(jù)庫里的描述
    protected string GetDescription()
    {
        try
        {
            string strComm = "select  photo_description from tab_photo where photo_id=1";
            SqlConnection myConn = new SqlConnection("user id=sa;passWord=123;Database =test;data source=z;");
            myConn.Open();
            SqlCommand myComm = new SqlCommand(strComm, myConn);
            SqlDataReader myReader = myComm.ExecuteReader();
            myReader.Read();
            return myReader.GetString(0);
        }
        catch
        {
            return "";
        }
    }

    [AjaxPro.AjaxMethod]
    //將description保存進數(shù)據(jù)庫 www.survivalescaperooms.com
    public bool UpdateDesc(string description)
    {
        try
        {
            string strComm = "update tab_photo set photo_description='" + description + "' where photo_id=1";
            SqlConnection myConn = new SqlConnection("user id=sa;password=123;Database =test;data source=z;");
            myConn.Open();
            SqlCommand myComm = new SqlCommand(strComm, myConn);
            myComm.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
    }
}

163photoTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="163photoTest.aspx.cs" Inherits="_163photoTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

<html xmlns="<head runat="server">
    <title>無標題頁</title>
<script language="
Javascript" type="text/javascript">
    function display()
    {
        document.getElementById('descfield').style.display='block';
        document.getElementById('descfield').value = document.getElementById('description').innerText ;
        document.getElementById('description').style.display='none';
        document.getElementById('save').style.display='block';
    }
    var s;
    function UpdateDesc()
    {
        s= document.getElementById("descfield").value;
        document.getElementById("descfield").value="正在保存";
        _163photoTest.UpdateDesc(s,UpdateDesc_callback);
    }
   
    function UpdateDesc_callback(res)
    {
        if (res)
        {
            document.getElementById('description').style.display='block';
            document.getElementById("description").innerText =s;
            document.getElementById('descfield').style.display='none';
            document.getElementById('save').style.display='none';
        }
    }
</script>
</head>
<body onload="document.getElementById('descfield').style.display='none';document.getElementById('save').style.display='none';">
    <form id="form1" runat="server">
    <div id="div1" onmousemove="this.style.backgroundColor='#C0C0FF';" onmouSEOut="this.style.backgroundColor='';" onclick="display()">
        <asp:Label ID="description" runat="server" Text="Label"></asp:Label>

    </div>
    <input type="text" id ="descfield"  />
        <input type="button" id="update" value="修改描述"  onclick="display()"/>
        <input type="button" id="save" value="保存修改"  onclick="UpdateDesc()"/>
        <br />
    </form>
</body>
</html>

出處:Coder at the Doorsill——風(fēng)中聆聽 BLOG


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 鄂托克旗| 普定县| 如皋市| 阿荣旗| 交口县| 伊金霍洛旗| 桂东县| 威信县| 理塘县| 揭东县| 南雄市| 莱州市| 衡南县| 宁城县| 禹城市| 久治县| 九江市| 金沙县| 棋牌| 宜兰市| 昂仁县| 甘孜县| 济阳县| 札达县| 临夏县| 泰和县| 临颍县| 菏泽市| 平潭县| 和龙市| 会理县| 永清县| 镇安县| 阜新| 都江堰市| 湄潭县| 中西区| 武宁县| 安岳县| 海阳市| 梅州市|