Writing /volume1/Web/Public/dokuwiki/data/log/deprecated/2024-11-14.log failed
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
study:javascript:start [2010/10/29 06:27] – banana | study:javascript:start [2015/02/19 07:07] (現在) – [Add Comma] banana | ||
---|---|---|---|
行 78: | 行 78: | ||
====== Merge Rowspan ====== | ====== Merge Rowspan ====== | ||
<code javascript> | <code javascript> | ||
- | function | + | (function ($) { |
- | { | + | $.extend($.fn, { |
- | var rowsCn = tableObj.rows.length; | + | |
- | + | | |
- | if(rowsCn-1 > rowIndex) | + | |
- | cellMergeProcess(tableObj, rowIndex, cellIndex); | + | } |
- | } | + | }); |
- | + | ||
- | function cellMergeProcess(tableObj, | + | |
- | { | + | |
- | var rowsCn = tableObj.rows.length; | + | |
- | var compareCellsLen = tableObj.rows[rowIndex].cells.length; | + | |
- | + | ||
- | // | + | |
- | var compareObj = tableObj.rows[rowIndex].cells[cellIndex]; | + | |
- | var compareValue = compareObj.innerHTML; | + | |
- | var cn = 1; | + | |
- | var delCells = new Array(); | + | |
- | var arrCellIndex = new Array(); | + | |
- | for(i=rowIndex+1; | + | |
- | { | + | |
- | var cellsLen = tableObj.rows[i].cells.length; | + | |
- | var bufCellIndex = cellIndex | + | |
- | //get collIndex of row | + | |
- | if(compareCellsLen != cellsLen) | + | |
- | { | + | // merge options |
- | bufCellIndex | + | this.o = $.extend(true, {}, $.impl.defaults, |
- | } | + | |
- | cellObj = tableObj.rows[i].cells[bufCellIndex]; | + | this.init(); |
- | + | }; | |
- | if(compareValue == cellObj.innerHTML) | + | |
- | { | + | |
- | //save the number of cell to delete. | + | |
- | delCells[cn-1] = tableObj.rows[i]; | + | |
- | //save the index of row cell. | + | |
- | arrCellIndex[cn - 1] = bufCellIndex; | + | |
- | cn++; | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | // | + | |
- | compareObj.rowSpan = cn; | + | |
- | + | ||
- | // | + | |
- | for(j=0; j < delCells.length; | + | |
- | { | + | |
- | delCells[j].deleteCell(arrCellIndex[j]); | + | |
- | } | + | |
- | + | ||
- | // | + | |
- | compareObj | + | |
- | compareValue = cellObj.innerHTML; | + | |
- | cn = 1; | + | |
- | delCells = new Array(); | + | |
- | arrCellIndex = new Array(); | + | |
- | } | + | |
- | } | + | |
- | //merge | + | |
- | compareObj.rowSpan = cn; | + | $.extend($.impl, |
- | //delete | + | |
- | for(j=0; j < delCells.length; j++) | + | rowIndex: 1, |
- | { | + | cellIndex: [1] |
- | delCells[j].deleteCell(arrCellIndex[j]); | + | }, |
- | } | + | prototype: { |
- | }// | + | init: function() { |
+ | // cell length before merging | ||
+ | | ||
+ | this.delArrays | ||
+ | this._scan(); | ||
+ | }, | ||
+ | _scan: function() { | ||
+ | var self = this, | ||
+ | indexArray = self.o.cellIndex; | ||
+ | $.each(indexArray, | ||
+ | self._cellMergeChk(o); | ||
+ | }); | ||
+ | }, | ||
+ | _cellMergeChk: | ||
+ | var self = this, | ||
+ | $target = $(self.target), | ||
+ | options = self.o, | ||
+ | cnt = 1, | ||
+ | compareObj = $target.find(' | ||
- | </code> | + | |
+ | $target.find(' | ||
+ | // compare cell's length | ||
+ | compareIndex = cellIndex; | ||
+ | cellsLen = $(this).find(' | ||
+ | if (self.tdLen != cellsLen) { | ||
+ | compareIndex = compareIndex - (self.tdLen - cellsLen); | ||
+ | } | ||
+ | cellObj = $(this).find(' | ||
+ | |||
+ | if (compareObj.html() == cellObj.html()) { | ||
+ | self.delArrays[cnt - 1] = cellObj; | ||
+ | cnt++; | ||
+ | } else { | ||
+ | // merge | ||
+ | self._merge(compareObj); | ||
+ | // initialize | ||
+ | compareObj = cellObj; | ||
+ | self.delArrays = []; | ||
+ | cnt = 1; | ||
+ | }//if~else | ||
+ | }); | ||
+ | }, | ||
+ | _merge: function(mergedCell) { | ||
+ | $.each(this.delArrays, | ||
+ | $(this).remove(); | ||
+ | }); | ||
+ | mergedCell.attr(' | ||
+ | } | ||
+ | }// | ||
+ | }); | ||
+ | |||
+ | })(jQuery); | ||
+ | |||
+ | </ | ||
行 153: | 行 162: | ||
- | ===== Usage ===== | ||
- | #merge first <td> \\ | ||
- | cellMergeChk(document.getElementById(" | ||
- | #merge second <td> \\ | ||
- | cellMergeChk(document.getElementById(" | ||
- | ===== reference | + | ===== Demo ===== |
- | http://blog.naver.com/bacchusl? | + | link to [[http://jsfiddle.net/loliqoop/ |
行 166: | 行 170: | ||
====== Add Comma ====== | ====== Add Comma ====== | ||
<code javascript> | <code javascript> | ||
- | function | + | function |
- | | + | return ("" |
- | if (number.length > 3) { | + | |
- | var mod = number.length % 3; | + | |
- | var output = (mod > 0 ? (number.substring(0, | + | |
- | for (i=0 ; i < Math.floor(number.length / 3); i++) { | + | |
- | if ((mod == 0) && (i == 0)){ | + | |
- | output += number.substring(mod+ 3 * i, mod + 3 * i + 3); | + | |
- | } else{ | + | |
- | output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3); | + | |
- | } | + | |
- | }//end for | + | |
- | return (output); | + | |
- | | + | |
- | return number; | + | |
- | | + | |
} | } | ||
</ | </ | ||
ちなみにカンマを除去するのは次のとおり | ちなみにカンマを除去するのは次のとおり | ||
<code javascript> | <code javascript> | ||
- | function | + | function |
- | var str = '' | + | return number.replace(/ |
- | var output=str.replace(/ | + | |
- | return output; | + | |
} | } | ||
- | |||
</ | </ | ||
行 261: | 行 248: | ||
</ | </ | ||
+ | ====== calculation the size of textarea ====== | ||
+ | textareaに入力した文字列のサイズを測る為に、次のソースを活用できる。 | ||
+ | <code javascript> | ||
+ | String.prototype.size = function() { | ||
+ | var _len = (!this) ? 0 : this.length; | ||
+ | var _size = 0; | ||
+ | |||
+ | for (i = 0; i < _len; i++) { | ||
+ | c = this.charCodeAt(i); | ||
+ | | ||
+ | if ((c >= 0x0000) && (c <= 0x007F) ) { | ||
+ | _size++; | ||
+ | } else if(c > 0x07FF){ | ||
+ | _size += 3; | ||
+ | } else { | ||
+ | _size += 2; | ||
+ | }//if~else | ||
+ | } | ||
+ | |||
+ | return _size; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== demo page ===== | ||
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | < | ||
+ | |||
+ | <script type=" | ||
+ | |||
+ | <script type=" | ||
+ | String.prototype.size = function() { | ||
+ | var _len = (!this) ? 0 : this.length; | ||
+ | var _size = 0; | ||
+ | |||
+ | for (i = 0; i < _len; i++) { | ||
+ | c = this.charCodeAt(i); | ||
+ | |||
+ | if ((c >= 0x0000) && (c <= 0x007F) ) { | ||
+ | _size++; | ||
+ | } else if(c > 0x07FF){ | ||
+ | _size += 3; | ||
+ | } else { | ||
+ | _size += 2; | ||
+ | }//if~else | ||
+ | } | ||
+ | |||
+ | return _size; | ||
+ | } | ||
+ | |||
+ | $(function(){ | ||
+ | $(" | ||
+ | $("# | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | </ | ||
+ | |||
+ | <style type=" | ||
+ | #console{ | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | <br> | ||
+ | <div id=" | ||
+ | </ | ||
+ | </ | ||
+ | ===== e-mail regexValidator ===== | ||
+ | eメールの一般的なvalidationの表現式は以下のようです。 | ||
+ | < | ||
+ | \\b(^_A-Za-z0-9-(\\._A-Za-z0-9-)*@(A-Za-z0-9-)+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov) | ||
+ | |(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name) | ||
+ | |(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2, | ||
+ | </ | ||
~~DISCUSSION~~ | ~~DISCUSSION~~ |