mootools架構【一】-Element篇: 進階應用程式舉例

來源:互聯網
上載者:User

說明:關於Element類更全面的執行個體會有後續補充, 請關注.

前台:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="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>mootools [一]--Element篇進階應用程式舉例</title>
     <script type="text/javascript"  language="javascript" src="mootools-1.2-core-jm.js"></script>
   
    <script type="text/javascript">
   
    //為頁添加操作事件-domready.
     window.addEvent("domready",function(){

    //為 btnSent 添加 單擊事件 .
    $('btnSent').addEvent('click',function(){
        if($('txtContent').innerText==''){
            alert('發送內容不能空!');
            return;
        }
       
        //Default2.aspx虛構一個頁面, 其實是將資料暫存, 然後提取並顯示在 messageBox中.
        var url='Default2.aspx';
        var postData=$("postMessage").toQueryString();
        new Ajax(url,{method:'post',onComplete:function(){
         
            $('messageBox').innerHTML += this.response.text;
            //這裡的 innerHTML 方法可以用 setHTML 代替, 因為 innerHTML 是DOM操作中用到的,  setHTML是mootools架構中新定義的.
            }
        }).request(postData);
    });

      });
</script>
</head>
<body>
     <div style="margin:auto;text-align:center; ">
        <div style=" width:650px; height:700px;">
            <div id="messageBox"></div>
            <hr />
            <form id="postMessage" method="post" name="postMessage" runat="server">
            <div>
                <ul>
                    <li style="list-style-type: none;">請輸入您的網名:&nbsp;&nbsp;&nbsp;&nbsp;<input ID="txtName" runat="server" value="填寫網名"/>
                    </li>
                </ul>
                <ul>
                    <li style="list-style-type: none;">請輸入要發送的內容:<textarea ID="txtContent" runat="server"  cols="20" rows="4"></textarea></li>
                </ul>
                <ul>
                    <li style="list-style-type: none;"><input type="button" ID="btnSent" runat="server" value="發送" onserverclick="btnSent_ServerClick"  /></li>
                </ul>
            </div>
            </form>
        </div>
    </div>
</body>
</html>

後台:

using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (!String.IsNullOrEmpty(txtName.Value) && !String.IsNullOrEmpty(txtContent.Value.Trim()))
            {

                string name = txtName.Value.Trim();
                string content = txtContent.Value.Trim();
                string msg = "<div><ul><li>" + name + "說:" + content + "</li></ul></div>";

                Response.Clear();
                Response.Write(msg);
                Response.End();
            }
            else if (!String.IsNullOrEmpty(txtContent.Value.Trim()) && String.IsNullOrEmpty(txtName.Value))
            {
                string name = "遊客";
                string content = txtContent.Value.Trim();
                string msg = "<div><ul><li>" + name + "說:" + content + "</li></ul></div>";
                Response.Clear();
                Response.Write(msg);
                Response.End();
            }
        }

    }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.