ExtJS Button的事件和方法定义

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ExtJs整理</title>
<link rel="stylesheet" type="text/css" href="ExtJs/resources/css/ext-all.css">
<script type="text/javascript" src="ExtJs/adapter/ext-base.js"></script>
<script type="text/javascript" src="ExtJs/ext-all.js"></script>
<script type="text/javascript" src="ExtJs/src/locale/ext-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
   Ext.onReady(function(){
		var button = new Ext.Button({
		    //构造函数的参数传入一个字面量- renderTo, text
			//minWidth最小宽度,无论字有多大都是100像素宽度
			//handler:指定一个函数句柄,在默认事件触发时的函数调用
			//此时的默认事件为click
			//这是事件定义的第一种方法
			//Ext.getBody().dom == document.body;
			renderTo: Ext.getBody(),
			text: "确定按钮",
			minWidth: 100,
			icon:"ExtJs/icon-error.gif", //按钮背景图片
			handler: function(){
				Ext.Msg.alert("按钮","巴塞罗那球迷");
			}
		});
   });
</script>
<body>
</body>
</html>


运行显示出来的按钮:

点击确定按钮:

 

提供的3种按钮方法

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ExtJs整理</title>
<link rel="stylesheet" type="text/css" href="ExtJs/resources/css/ext-all.css">
<script type="text/javascript" src="ExtJs/adapter/ext-base.js"></script>
<script type="text/javascript" src="ExtJs/ext-all.js"></script>
<script type="text/javascript" src="ExtJs/src/locale/ext-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
   Ext.onReady(function(){
		var buttonA = new Ext.Button({
			renderTo: Ext.getBody(),
			text: "确定按钮",
			minWidth: 100,
			icon:"ExtJs/icon-error.gif", //按钮背景图片
			handler: function(){
				Ext.Msg.alert("按钮","巴塞罗那球迷");
			}
		});
		//text是Ext.Button的只读属性
		//alert(button.text);
		//setText是Ext.Button的设置Text方法
		buttonA.setText("[A]<替换确定按钮>");  //确定被替换取消
		//listeners是在对象在被初始化前,就将一系列事件定义的手段
		//这是事件定义的第二种方法(推荐程度5颗星)
		var buttonB = new Ext.Button({
			renderTo: Ext.getBody(),
			text: "[B]Listeners 按钮测试",
			minWidth:100,
			listeners:{
				"click":function(){
					Ext.Msg.alert("按钮","Listeners 按钮测试");
				}
			}
		});
		//这是事件定义的第三种方法
		var buttonC = new Ext.Button({
			renderTo: Ext.getBody(),
			text: "[C]On方法的事件定义",
			minWidth:100
		});
		buttonC.on("click", function(){
			Ext.Msg.alert("按钮","On方法的事件定义");
		});
   });
</script>
<body>
</body>
</html>


运行结果:

点击[A]点击[B]点击[C]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值