Extjs4学习笔记-Ext.EventManager

Ext.EventManager.on(el, eventName, fn[, scope, options]) 

 

 

实现输入框获得焦点时,不显示“请输入”,失去焦点,并且没有输入任何字符时,显示“请输入”

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Console Test</title>
		
		<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css" />
		<script type="text/javascript" src="../extjs/bootstrap.js"></script>
		<script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>
		
		<script type="text/javascript">
			
			Ext.onReady(function() {
				var focus = function(e, el) {
				if(el.value == "请输入") {
					el.value = "";
					}
				}
				
				var blur = function(e, el) {
					if(el.value == "") {
						el.value = "请输入";
					}
				}
				
				//一次只绑定一个事件
				Ext.EventManager.on("input1", "focus", focus);
				Ext.EventManager.on("input1", "blur", blur);
				
				//一次绑定多个事件
				Ext.EventManager.on("input2", {
					focus: focus,
					blur: blur
				});
				
				//一次绑定多个事件,使用不同配置项的方式为id为input3的输入框绑定事件
				Ext.EventManager.on("input3", {
					focus: {fn: focus},
					blur: {fn: blur}
				});
								
			});
			
		</script>
		
		
	</head>
	<body>
		<input type="text" id="input1" value="请输入" />
		<input type="text" id="input2" value="请输入" />
		<input type="text" id="input3" value="请输入" />
	</body>
</html>

 

你可能感兴趣的:(Extjs4学习笔记-Ext.EventManager)