|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
| |
| 让 SortTable 和 Asp.net Ajax 和睦相处 |
|
相信很多人都可能用过SortTable这个对Table元素进行排序的JS类库。 dZ4Linux联盟 dZ4Linux联盟 SortTable只需要设置Table的class就可以实现简单的应用。如果需要复杂引用,可以到下面的下载地址链接里面找到答案。这里就不再多说了。 dZ4Linux联盟 dZ4Linux联盟 下载地址:http://www.kryogenix.org/code/browser/sorttable/ dZ4Linux联盟 dZ4Linux联盟 可是如果在引用了SortTable同时用到了Asp.net Ajax。呵呵,这下绝对热闹。好像仇敌一样。 dZ4Linux联盟 dZ4Linux联盟 错误提示: dZ4Linux联盟 Sys.ArgumentTypeException: Object of type ‘Object’ cannot be converted to type ‘Array’ dZ4Linux联盟 dZ4Linux联盟 经过几个小时的努力,通过FireFox+FireBug的协力帮助,终于找到症结。主要是SortTable里面的forEach实现和Asp.net Ajax的forEach实现有冲突。 dZ4Linux联盟 当然,要让Ajax.net Ajax里面的forEach失效可不是什么容易的事情。只能让SortTable里面的forEach失效了。通过多SortTable里面的forEach进行分析,最终舍弃了SortTable里面的forEach实现并且将实现代码去除,然后将forEach改成了for实现。终于……和睦相处了。 dZ4Linux联盟 当然还可以有更好的改法,就是将forEach的方法改名,但是发现SortTable引用的forEach也就那么一点,于是用for了。 dZ4Linux联盟 有两处需要修改: dZ4Linux联盟 dZ4Linux联盟 第一处: dZ4Linux联盟 //原始代码 dZ4Linux联盟 // Array.forEach(document.getElementsByTagName('table'), function(table) { dZ4Linux联盟 // if (table.className.search(/\bsortable\b/) != -1) { dZ4Linux联盟 // sorttable.makeSortable(table); dZ4Linux联盟 // } dZ4Linux联盟 // }); dZ4Linux联盟 // alert(document.getElementsByTagName('table').length); dZ4Linux联盟 dZ4Linux联盟 // //修改代码 dZ4Linux联盟 for(i=0;i<document.getElementsByTagName('table').length;i++) dZ4Linux联盟 { dZ4Linux联盟 // alert(document.getElementsByTagName('table').length); dZ4Linux联盟 table=document.getElementsByTagName('table')[i]; dZ4Linux联盟 if (table.className.search(/\bsortable\b/) != -1) dZ4Linux联盟 { dZ4Linux联盟 sorttable.makeSortable(table); dZ4Linux联盟 } dZ4Linux联盟 }; dZ4Linux联盟 dZ4Linux联盟 第二处: dZ4Linux联盟 //原始代码 dZ4Linux联盟 //forEach(theadrow.childNodes, function(cell) { dZ4Linux联盟 // if (cell.nodeType == 1) { dZ4Linux联盟 // cell.className = cell.className.replace('sorttable_sorted_reverse',''); dZ4Linux联盟 // cell.className = cell.className.replace('sorttable_sorted',''); dZ4Linux联盟 // } dZ4Linux联盟 // }); dZ4Linux联盟 //修改代码 dZ4Linux联盟 dZ4Linux联盟 for(i=0;i<theadrow.childNodes.length;i++) dZ4Linux联盟 { dZ4Linux联盟 var cell=theadrow.childNodes[i]; dZ4Linux联盟 if (cell.nodeType == 1) { // an element dZ4Linux联盟 cell.className = cell.className.replace('sorttable_sorted_reverse',''); dZ4Linux联盟 cell.className = cell.className.replace('sorttable_sorted',''); dZ4Linux联盟 } dZ4Linux联盟 }; dZ4Linux联盟 dZ4Linux联盟 然后呵呵……好了 dZ4Linux联盟 dZ4Linux联盟 下面是我改好的JS包,而且将编码规则改成了UTF-8,这样可以去除因为网页编码的问题。给大家都用用 dZ4Linux联盟 dZ4Linux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|