2010-11-20 17 views
0

テーブルセルのonmouseeventに問題があります。 私がやっていることは、jqueryの助けを借りてhtml table cellを削除して作成することです。ページがロードされると、このイベントは完全に正常に発生します。しかし、同じ位置に再びテーブルセルを取り出して挿入しても、onmouseoverイベントは発生しません。以下は私が行ったコードです...onmouseoverイベントがテーブルセルで発生していません

var ModularAdHolderCell = ''; 
var MergedCellValues = new Array(); 
$('#our_table tr').each(function (i, el) { 
    for (var cellCnt = 0; cellCnt < this.cells.length; cellCnt++) { 
    if ($(this.cells[cellCnt]).attr('class') == 'highlighted' || $(this.cells[cellCnt]).attr('class') == 'OrangeBackground highlighted') { 
      var id = $(this.cells[cellCnt]).attr('id'); 
      ModularAdHolderCell = id; 
      id = 'hdn_' + id; 
      var MergedCells = $(this.cells[cellCnt]).find('input:hidden').val(); 
      if (MergedCells != '') 
       MergedCellValues = MergedCells.trim().split('='); 
     } 
    } 
}); 

var row = document.all.our_table.rows[0]; 
var TotalCellInRow = row.cells.length; 
var Cell = row.insertCell(TotalCellInRow); 
var element1 = document.createElement("input"); 
element1.type = "hidden"; 
element1.id = "hdn_" + MergedCellValues[cnt]; 

row.cells(TotalCellInRow).setAttribute('onmouseover', 'MOuseOver(this)'); 
row.cells(TotalCellInRow).setAttribute('onmouseout', 'MouseOut()'); 
row.cells(TotalCellInRow).setAttribute('onmousemove', 'MOuseOver(this)'); 
row.cells(TotalCellInRow).setAttribute('onmouseenter', 'MOuseOver(this)'); 

row.cells(TotalCellInRow).setAttribute('unitheight', Unitwidth); 
row.cells(TotalCellInRow).setAttribute('unitwidth', UnitHeight); 
row.cells(TotalCellInRow).setAttribute('id', MergedCellValues[cnt]); 

row.cells(TotalCellInRow).setAttribute('width', Unitwidth); 
row.cells(TotalCellInRow).setAttribute('height', UnitHeight); 
row.cells(TotalCellInRow).appendChild(element1); 

$(row).find('#' + MergedCellValues[cnt] + '').attr('onmouseover', 'MOuseOver(this)'); 
$(row).find('#' + MergedCellValues[cnt] + '').attr('onmouseout', 'MouseOut()'); 
$(row).find('#' + MergedCellValues[cnt] + '').attr('onmousemove', 'MOuseOver(this)'); 
$(row).find('#' + MergedCellValues[cnt] + '').attr('onmouseenter', 'MOuseOver(this)'); 

ここでMergedCellValuesはセルIDの配列で、上記のコードはセルのループ内にあります。

誰でもセルのonmouseoverイベントが発生しない理由を伝えることはできますか?

+0

@Ronak;そのような質問のために、あなたはこれをテストしているブラウザを指定することがほとんど常に重要です。それは何が起こっているのか手掛かりを与えるかもしれません。 – BeemerGuy

+0

あなたの 'MOuseOver'関数はどのように見えますか? –

+0

@BeemerGuy:私はIE8を使用しています。奇妙なことは、サファリのためにうまくいきます。 – Ronak

答えて

1

アトリビュートを設定するだけでイベントハンドラをアタッチする方法ではありません。単純化して処理を高速化し、.setAttribute('onmouseover', 'MOuseOver(this)');ロジックをすべて削除してから、すべて8行を削除してから、このすべてを処理する<table>へのハンドラのセット:

$("#our_table") 
    .delegate("td", "mouseover mousemove mouseenter", MOuseOver) 
    .delegate("td", "mouseout", MouseOut); 

その後、あなたのMOuseOverMouseOut機能では、単にセルを参照するためにthisを使用しています。

これが湧き上がっていない...ごとのセルにそれらを結合するための必要を他のマウスイベントをリッスンする<table>要素にハンドラをアタッチし、これははるか安価で、合成電流と新しい細胞に取り組んでいます。

+0

多くの方に感謝ニック...これを試してみましょう.... – Ronak

+0

@Ronak - jQuery 1.4.2以降で更新しました.1.4.3以上の構文では動作しません...上記のコードはうまくいくはずです。あなたが渡しているパラメータではなく、あなたの関数で 'this'を使用してください。 –

関連する問題