`
tsailer
  • 浏览: 53049 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

add event to all the dom elements in one page except one dom

    博客分类:
  • JS
阅读更多
<!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>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <style type="text/css">
  <!--
	div{width:100px;height:100px;_padding-left:26px;}
	#id_click{border:1px solid #FddD33;float:left;}
	.sss{border:1px solid #F0dD33;float:left;}
	.exceptme{border:1px solid #00dD33;float:left;}
	.includeme{border:1px solid #Fd0033;float:left;}
  -->
  </style>
 </head>

 <body>
  <div id="id_click"></div>
  <div id="sss" class="sss"></div>
  <div id="exceptme" class="exceptme"></div>
  <div id="includeme" class="includeme"></div>
 </body>
 <script src="http://www.pingan.com/app_js/jquery-1.3.2.js" type="text/javascript"></script>
 <script language="JavaScript" type="text/javascript">
 <!--
	function domEvent(){}
	
	domEvent.prototype = {
		objtoarr:function (obj){
			var arr = [],m=0;
			if(obj.length>1){
				while(m<obj.length){
					arr[m] = obj[m];
					m++;
				}
			}else{
				arr[0]=obj
			}
			return arr;
		}
		,dom_exceptjs:function (){
			var obj_dom = document.getElementsByTagName("body").item(0).children;
			var obj_script = document.getElementsByTagName("script");
			var m=0, n=0, arr_dom=[], arr_script=[];
			arr_dom = this.objtoarr(obj_dom);
			arr_script = this.objtoarr(obj_script);
			for(var i=0; i<arr_dom.length;i++){
				for(var j=0;j<arr_script.length;j++){
					if(arr_dom[i]==arr_script[j]){
						arr_dom.splice(i,1);
					}
				}
			}
			return arr_dom;
		}
		,removeunusedom:function (total, goal){
			for(var i=0;i<total.length;i++){
				if(total[i]==goal){
					total.splice(i,1);
					return total;
				}
			}
			return false;
		}
		,addEvent:function (dom,type,func){
			if(document.attachEvent){
				dom.attachEvent("on"+type,func);//ie
			}
			if(document.addEventListener){
				dom.addEventListener(type,func,true);//mozillar
			}
		}
		,removeEvent:function (dom,type,func){
			if(document.attachEvent){
				dom.detachEvent("on"+type,func);
			}
			if(document.addEventListener){
				dom.removeEventListener(type,func,true);
			}
		}
	}
var actdemo = new domEvent();
(function(){
	var toa_AddEvent = actdemo.removeunusedom(actdemo.objtoarr(document.getElementsByTagName("div")),document.getElementById("exceptme"));
	for(var i=0;i<toa_AddEvent.length;i++){
	//alert("00");
		/*actdemo.addEvent(toa_AddEvent[i],"click",function(){
			//var dom = toa_AddEvent[i];
			alert(this.getAttribute("id"));
		})*/
		actdemo.addEvent(toa_AddEvent[i],"click",function(e){
			var target = e.srcElement || e.target;
			alert(target.getAttribute("id"));
		})
	}
})()

 //-->
 </script>
</html>

分享到:
评论

相关推荐

    HTML, XHTML, and CSS All-in-one Desk Reference For Dummies

    These eight minibooks get you started, explain standards, and help you connect all the dots to create sites with pizzazz. This handy, one–stop guide catches you up on XHTML basics and CSS ...

    HTML, CSS & JavaScript Web Publishing in One Hour a Day 7th 第7版 0分

    In just one hour a day, you’ll learn the skills you need to design, create, and maintain a professional-looking website. No previous experience required. By following each short, one-hour lesson in ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: After deleting the selected points in the TFlexPanel.DeleteSelectedPoints the all figures with one point also deleted. - FIX: When the curve contain more then one figure and they were all ...

    JQuery In Action.PDF

    - **The jQuery Wrapper:** When you use JQuery to select or create elements, you receive a wrapper object that contains all the matched DOM elements. This wrapper provides a consistent interface for ...

    dom4j常用方法

    dom4j常用方法 i.SAXReader sr = new SAXReader(); 生成解析器对象 ii.解析器对象.read(file对象); 解析文件生成Document对象 iii.文档对象.getRootElement() 获取跟元素节点 iv.元素节点.elements() 获取到指定...

    Beginning JavaScript with DOM Scripting and Ajax: Second Editon

    This completely updated second edition covers everything you need to know to get up-to-speed with JavaScript development and add dynamic enhancements to web pages, right from the basics. As well as ...

    Learn CSS in One Day and Learn It Well (Volume 2)

    Concepts are presented in a "to-the-point" style to cater to the busy individual. With this book, you can learn HTML and CSS in just one day and start coding immediately. How is this book different.....

    All In 1 Sprite Shader 1.7.unitypackage

    All In 1 Sprite Shader is an all in one solution to add cool popular sprite and UI effects to your project in the easiest and fastest way possible. It includes 40+ combinable effects. The ...

    Beginning JavaScript with DOM Scripting and Ajax (pdf + ePub)

    How to access and update part of the page using code. How to use JavaScript to communicate with the server and retrieve data. How to use JavaScript to for form validation and user feedback. How to use...

    All In 1 Sprite Shader v3.3.unitypackage

    ✨All In 1 Sprite Shader✨ is an all in one solution to add cool popular sprite and UI combinable effects to your project in the easiest and fastest way possible.

    dom4j_dom4j1.6.1安装包_

    rootElement.addElement("child").addText("Hello, DOM4J!"); ``` 这段代码首先创建了一个`DocumentFactory`实例,然后通过它创建了一个新的XML文档,并添加了一个根元素`root`,在根元素下又添加了一个子元素`child...

    ComponentOne Studio for WinForms 2013 v1 1/5

    Download the 2013 v1 update to access the new TileControl to achieve a Windows 8 look and feel in your desktop apps as well as feature enhancements for Reports, Editor, and Scheduler. See the what's ...

    ComponentOne Studio for WinForms 2013 v1

    Download the 2013 v1 update to access the new TileControl to achieve a Windows 8 look and feel in your desktop apps as well as feature enhancements for Reports, Editor, and Scheduler. See the what's ...

    ComponentOne Studio for WinForms 2013 v1 5/5

    Download the 2013 v1 update to access the new TileControl to achieve a Windows 8 look and feel in your desktop apps as well as feature enhancements for Reports, Editor, and Scheduler. See the what's ...

    JSP Simple Examples

    This directive has only one attribute named as file, which is used to include a file in the jsp page at the translation time. &lt;jsp:include page = " "&gt;:- This is known as the include standard action....

    Manning jQuery in Action.pdf

    The book explains how jQuery facilitates this separation by enabling the use of event delegation and by making it easy to add behavior to elements without hard-coding JavaScript directly into the ...

    Unity3DBookPageCurl-master翻书插件

     If you want to call any function when any page flipped add it to the OnFlip Event List.  If you want to resize the area that the user can drag the page from it, open the Book node in inspector ...

    SSD7 选择题。Multiple-Choice

    (b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...

Global site tag (gtag.js) - Google Analytics