忍者ブログ
まにょのITメモ
[77]  [76]  [75]  [74]  [73]  [72
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


<html>
    <head>
        <title>お薬一覧</title>
<script language="javascript">

<!--

// クラス定義
var RowInfo = function(sortKey, rowObj) {
 this.sortKey = sortKey;
 this.rowObj = rowObj;
 this.toString = function() {
     window.alert(this.sortKey + " " + this.rowObj.innerText);
 };
}

function sample(tableName){
 this.table = document.getElementById(tableName);
 this.tbody = this.table.getElementsByTagName('tbody')[0];
 this.rows = this.tbody.getElementsByTagName('tr');
 this.cells = this.tbody.getElementsByTagName('td');

 this.thead = this.table.getElementsByTagName('thead')[0];
 this.headers = this.thead.getElementsByTagName('th');

 for(i=0; i<this.headers.length; i++){
alert(1);
alert(this.headers[i].innerText);
//  this.headers[i].addEvent('click', function(i){alert(i)});
alert(2);
//   this.headers[i].addEvent('mouseover',function(i){this.headers[i].addClass(this.options.overCl)}.pass(i,this));
//   this.headers[i].addEvent('mouseout',function(i){this.headers[i].removeClass(this.options.overCl)}.pass(i,this));
//   this.headers[i].setStyle('cursor','pointer');
 }
alert(3);
 // ヘッダーにonClickを埋め込む
// for(i=0; i<this.headers.length; i++){
//  var header = this.headers[i];
//  alert(header.innerText);
//  var onClickAttr = document.createAttribute("onclick");
//  onClickAttr.nodeValue ="alert()";
//  header.setAttributeNode(onClickAttr);
//  alert(77777);
// }

 // オブジェクトの配列
 var rowObjList = new Array();

 // 全行の情報をリストにつめる
 for(i=0; i<this.rows.length; i++){
  var row = this.rows[i];
  // カラムの2つ目の値を取得する。
  var cellValue = row.getElementsByTagName('td')[0];
  rowObjList.push(new RowInfo(cellValue.innerText, row));
 }

 // ソート処理を実施
 rowObjList.sort(compare);

 for(i =0; i<rowObjList.length; i++){
  var newRow = rowObjList[i].rowObj;
  this.tbody.appendChild(newRow);
 }
}

//数値を取得
function getNum(num){
  if( num.match(/^(\-?((\d{1,3}(,\d\d\d)+)|\d+)(\.\d+)?)(.*)$/i) ){
    nn = RegExp.$1;
    nv = RegExp.$6;
    if(nn == ''){
       nn = '0';
    }
    return(new Array(nn,nv));
  }else{
    return(new Array('0',num));
  }
}


function compare(a1, b1){
    if(1){
      a1 = Number(a1.sortKey);
      b1 = Number(b1.sortKey);
    }else{
      a1 = String(a1.sortKey);
      b1 = String(b1.sortKey);
    }
    if(0){
      return a1 > b1 ? -1 : a1 < b1 ? 1 : 0;
    }else{
      return a1 < b1 ? -1 : a1 > b1 ? 1 : 0;
    }
}
//-->
</script>
    </head>
    <body>
           <input type="button" name="add" value="追加" onclick="sample('tableId')">
        <table id="tableId" border="1">
   <thead>
          <tr>
     <th>No</th><th>名前</th><th>単価</th>
       </tr>
   </thead>
   <tbody>
          <tr>
     <td>20</td><td>りんご</td><td>500</td>
          </tr>
       <tr>
     <td>5</td><td>みかん</td><td>250</td>
          </tr>
       <tr>
     <td>3</td><td>ぶどう</td><td>750</td>
          </tr>
    <tr>
     <td>10</td><td>とまと</td><td>150</td>
          </tr>
    <tr>
     <td>a</td><td>白菜</td><td>800</td>
          </tr>
   </tbody>
        </table>
    </body>
</html>

PR
この記事にコメントする
お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
この記事へのトラックバック
この記事にトラックバックする:
この記事のURL:
HOME Web.xml >>
忍者ブログ * [PR]