2013年5月18日

common XSLT solution in all browser

摘要: 1 function transform(context, xslt) { 2 if (typeof XSLTProcessor != "undefined") { 3 var processor = new XSLTProcessor(); 4 processor.importStylesheet(xslt); 5 6 var result = processor.transformToDocument(context); 7 return (new XMLSerializer... 阅读全文

posted @ 2013-05-18 17:14 雷音 阅读(142) 评论(0) 推荐(0) 编辑

common Xpath solution across browser

摘要: //select single node 1 function selectsingleNode(context, expression, namespaces) { 2 var doc = (context.nodeType != 9 ? context.ownerDocument : context); 3 4 if (typeof doc.evaluate != "undefined") { 5 var nsresolver = null; 6 if (namespaces instanceof Objec... 阅读全文

posted @ 2013-05-18 17:02 雷音 阅读(198) 评论(0) 推荐(0) 编辑

a cross-broswer solution for serialize xml dom

摘要: 1 function serializeXml(xmldom) { 2 3 if (typeof XMLSerializer != "undefined") { 4 return (new XMLSerializer()).serializeToString(xmldom); 5 } else if (document.implementation.hasFeature("LS", "3.0")) { 6 var implementation = document.implementation; 7 ... 阅读全文

posted @ 2013-05-18 00:54 雷音 阅读(131) 评论(0) 推荐(0) 编辑

a cross-broswer solution for parse xml fragment

摘要: 1 function parseXml(xml) { 2 var xmldom = null; 3 4 if (typeof DOMParser != "undefined") { 5 xmldom = (new DOMParser()).parseFromString(xml, "text/xml"); 6 var errors = xmldom.getElementByTagName("parsererror"); 7 if (errors.length) { 8 ... 阅读全文

posted @ 2013-05-18 00:25 雷音 阅读(157) 评论(0) 推荐(0) 编辑

2013年5月16日

serialize form in javascript

摘要: 1 function serialize(form) { 2 var parts = new Array(); 3 var field = null; 4 5 for (var i = 0, len = form.elements.length; i < len; i++) { 6 field = form.elements[i]; 7 8 switch (field.type) { 9 case "select-one":10 ... 阅读全文

posted @ 2013-05-16 20:50 雷音 阅读(174) 评论(0) 推荐(0) 编辑

event related object in javascript

摘要: 1 var EventUtil = { 2 3 addHandler: function (element, type, handler) { 4 if (element.addEventListener) { 5 element.addEventListener(type, handler, false); 6 } else if (element.attachEvent) { 7 element.attachEvent("on" + type, ... 阅读全文

posted @ 2013-05-16 17:28 雷音 阅读(248) 评论(0) 推荐(0) 编辑

2013年5月15日

figure element size using javascript

摘要: 1 //get element size 2 3 function getElementLeft(element) { 4 var actualLeft = element.offsetLeft; 5 var current = element.offsetParent; 6 7 while (current !== null) { 8 actualLeft += current.offsetLeft; 9 current = current.offsetParent;10 ... 阅读全文

posted @ 2013-05-15 21:05 雷音 阅读(184) 评论(0) 推荐(0) 编辑

check plugin in browser

摘要: 1 //invalid in IE 2 function hasPlugin(name) { 3 name = name.toLowerCase(); 4 for (var i = 0; i < navigator.plugins.length; i++) { 5 if (navigator.plugins[i].name.toLowerCase().indexOf(name) > -1) { 6 return true; 7 } 8 } 9 10 ... 阅读全文

posted @ 2013-05-15 17:04 雷音 阅读(144) 评论(0) 推荐(0) 编辑

userAgent string detection in javascript

摘要: 1 var client = function () { 2 3 //browser engine 4 var engine = { 5 ie: 0, 6 gecko: 0, 7 webkit: 0, 8 khtml: 0, 9 opera: 0, 10 //full version 11 ver: null 12 }; 13 14 //br... 阅读全文

posted @ 2013-05-15 16:36 雷音 阅读(202) 评论(0) 推荐(0) 编辑

2013年5月14日

several way to implement inheritance in javascript

摘要: 1 //1.prototype chain inheritance 2 function SuperType() { 3 this.property = true; 4 } 5 SuperType.prototype.getSuperValue = function () { 6 return this.property; 7 }; 8 function SubType() { 9 this.subproperty = false;10 }11 12 //inherited from Su... 阅读全文

posted @ 2013-05-14 23:45 雷音 阅读(145) 评论(0) 推荐(0) 编辑

导航