Ext 与 Jquery 的结合应用

废话:

        我一直主张各司其职,页面的UI就应该由专门的人去做(flash,css等)而不应该交给js来完成,不过最近在周围朋友的影响下对ext也充满了好奇,毕竟ext的UI表现还是很优美的(本人是个大老粗对审美就这点品味了),于是开始决定学习ext并将其记录下来,希望对他人有用。

 

说明:

       本人是jquery的的fans,好在extjquery并不冲突,在写演示代码时我将主要使用jquery+ext

 

正题:

       今天刚开始学习ext于是从最简单的对话框开始。

       首先搭建好ext环境(HTML中引入对应的js文件)

Js代码 复制代码
  1. <style>   
  2.     @import  "../resources/css/ext-all.css";          
  3. </style>   
  4. <script src="../adapter/jquery/jquery.js"></script>   
  5. <script src="../adapter/jquery/ext-jquery-adapter.js"></script>   
  6. <script src="../ext-all.js"></script>  
    <style>
        @import  "../resources/css/-all.css";       
    </style>
    <script src="..///.js"></script>
    <script src="..///--.js"></script>
    <script src="../-all.js"></script>

 其中css为ext的样式,如果没有这个文件那ext的界面会奇丑无比。

由于我喜欢用jquery于是我导入了jquery.js与ext-jquery-adapter.js文件

这里可以根据个人喜欢进行修改在extadapter文件夹下有prototype,yui,extjquery四种可以选择。

ext-all.js是ext主要功能的合集

搭建好环境后就可以开始写代码啦。

ext中所有对话框都有Ext.MessageBox进行管理,可以缩写成Ext.Msg。

一个简单的alert我们可以调用Msg中的alert方法

Js代码 复制代码
  1. <body>   
  2. <button id="generalBtn">普通对话框</button><br/>   
  3.  $("#generalBtn").click(function(){   
  4.                 Ext.Msg.alert("title""hello word",function(btn){alert(btn)});   
  5.  });   
  6. </body>  
<body>
<button id="generalBtn">普通对话框</button><br/>
 $("#generalBtn").click(function(){
                .Msg.alert("title", "hello word",function(btn){alert(btn)});
 });
</body>

 alert共有4个参数前2个是必填的,第三个是回调函数当对话框关闭时将调用该函数,第四个参数是回调函数的作用域(这个参数具体什么用我目前不清楚,有清楚的朋友还望指点一二)。

Msg还包括了一些常用的对话框比如confirm,prompt基本用法与alert相同

Java代码 复制代码
  1.  <button id="confirmBtn">确认对话框</button><br/>   
  2.  <button id="promptBtn">输入对话框</button><br/>   
  3. $("#confirmBtn").click(function(){   
  4.                 Ext.MessageBox.confirm("title""hello word",function(btn){   
  5.                     alert(btn);   
  6.                 });        
  7. });   
  8. $("#promptBtn").click(function(){   
  9.                 Ext.MessageBox.prompt("title""输入内容", function(btn,text){alert("用户按下的按钮是:"+btn+"用户输入的内容是"+text)},nulltrue'value');              
  10. });  
 <button id="confirmBtn">确认对话框</button><br/>
 <button id="promptBtn">输入对话框</button><br/>
$("#confirmBtn").click(function(){
                .MessageBox.confirm("title", "hello word",function(btn){
                    alert(btn);
                });     
});
$("#promptBtn").click(function(){
                .MessageBox.prompt("title", "输入内容", function(btn,text){alert("用户按下的按钮是:"+btn+"用户输入的内容是"+text)},null, true, 'value');           
});

 Msg还包括progress与wait对话框,用法也比较简单

Js代码 复制代码
  1. <button id="progressBtn">progressBtn</button><br/>   
  2. <button id="waitBtn">wait</button><br/>   
  3. function time (i, messageBox){   
  4.             messageBox.updateProgress(i,"progressText""进程");   
  5.             if(i>=1){   
  6.                 messageBox.hide();   
  7.                 return;   
  8.             }else{   
  9.               setTimeout(time, 500, i+0.1,messageBox);     
  10.             }   
  11.         }   
  12. $("#progressBtn").click(function(){   
  13.                  var pro = Ext.MessageBox.progress("title""进程""progressText");   
  14.                  time(0.1,pro);   
  15.             });   
  16.             $("#waitBtn").click(function(){   
  17.                 Ext.MessageBox.wait("等待中...""title");   
  18.             });  
<button id="progressBtn">progressBtn</button><br/>
<button id="waitBtn">wait</button><br/>
function time (i, messageBox){
            messageBox.updateProgress(i,"progressText", "进程");
            if(i>=1){
                messageBox.hide();
                return;
            }else{
              setTimeout(time, 500, i+0.1,messageBox);  
            }
        }
$("#progressBtn").click(function(){
                 var pro = .MessageBox.progress("title", "进程", "progressText");
                 time(0.1,pro);
            });
            $("#waitBtn").click(function(){
                .MessageBox.wait("等待中...", "title");
            });

 Msg中其实最核心的show方法,他可以根据配置对象定义一个自定义的对话框,其实刚才所见的所有对话框都是ext帮我们事先定义好的而已,其内部都是调用show方法

show方法很简单只有一个参数就是配置对象,但这个对象的属性很多,具体内容可以参考API

调用方法如下

Js代码 复制代码
  1. <BUTTON ID="showBtn">自定义对话框</BUTTON>   
  2.       <button id="testRBtn" style="float:right">右边的按钮</button>   
  3. $("#showBtn").click(function(){   
  4.                 Ext.MessageBox.show({   
  5.                     animEl:"testRBtn",   
  6.                     buttons:Ext.MessageBox.YESNOCANCEL,   
  7.                     title:"自定义对话框",   
  8.                //     fn:callback,   
  9.                     icon:Ext.MessageBox.WARNING,   
  10.                     msg:"o(∩_∩)o...哈哈"  
  11.                 });   
  12.             });  
<BUTTON ID="showBtn">自定义对话框</BUTTON>
      <button id="testRBtn" style="float:right">右边的按钮</button>
$("#showBtn").click(function(){
                .MessageBox.show({
                    animEl:"testRBtn",
                    buttons:.MessageBox.YESNOCANCEL,
                    title:"自定义对话框",
               //     fn:callback,
                    icon:.MessageBox.WARNING,
                    msg:"o(∩_∩)o...哈哈"
                });
            });
 
最后把项目的一个页面实例贴附到这里供大家参考:
 
 
ExpandedBlockStart.gif 代码
 1  <% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " BackStateManage.aspx.cs "  Inherits = " zsWeb.admin.BackStateManage "   %>
 2 
 3  <! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
 4 
 5  < html xmlns = " http://www.w3.org/1999/xhtml "   >
 6  < head runat = " server " >
 7       < title ></ title >
 8      
 9       <!--  jquery references context  -->
10       < link href = " ../CSS/cupertino/jquery-ui-1.8.custom.css "  rel = " stylesheet "  type = " text/css "   />
11       < script src = " ../JS/jquery-1.4.1-vsdoc.js "  type = " text/javascript " ></ script >
12       < script src = " ../JS/jquery-ui-1.8.custom.min.js "  type = " text/javascript " ></ script >
13       < script src = " ../JS/jquery-ui-1.8.custom.min-vsdoc.js "  type = " text/javascript " ></ script >
14      
15       <!--  Ext js references context  -->
16       < link href = " ../Plusins/resources/css/ext-all.css "  rel = " stylesheet "  type = " text/css "   />
17       < script src = " ../Plusins/ExtJS/ext-jquery-adapter.js "  type = " text/javascript " ></ script >
18       < script src = " ../Plusins/ExtJS/ext-all.js "  type = " text/javascript " ></ script >
19 
20  </ head >
21  < body >
22       < form id = " form1 "  runat = " server " >
23       < div >
24  < input type = " button "  id = " showBtn "  value = " showBtn "   />
25  < input type = " button "  id = " waitBtn "  value = " waitBtn "   />
26 
27       < script type = " text/javascript "  language = " javascript " >
28          $( " #showBtn " ).click(function() {
29              Ext.MessageBox.show({
30                  animEl:  " testRBtn " ,
31                  buttons: Ext.MessageBox.YESNOCANCEL,
32                  title:  " 自定义对话框 " ,
33                   //      fn:callback,   
34                  icon: Ext.MessageBox.WARNING,
35                  msg:  " o(∩_∩)o...哈哈 "
36              });
37          }); 
38       </ script >
39       </ div >
40       </ form >
41  </ body >
42  </ html >
43 

 

转载于:https://www.cnblogs.com/China-Dragon/archive/2010/05/03/1726305.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值