私は 2 つのページを持っていますが、どちらも同様の構造を持っています - 次のような id タグを持つテーブル
<TABLE id="assetsTable1" width="100%" class="tableWrapDataClass"> ...
と
<table id="vocationalRevenueTable" class="revenue" width="100%"> ...
どちらのページもほぼ同じ JavaScript コードを使用しています。しかし、グローバル変数の値はページ 2 で異なる動作をします!
これはページ 1 のスニペットです。
<script type="text/javascript" src="templates/footer.js"></script>
<script type="text/javascript" src="script/jquery-1.8.1.js"></script>
<script type="text/javascript" src="script/scripts.js"></script>
<script>
$(document).ready(function() {
var assetsTable1 = $('#assetsTable1');
var assetsTable2 = $('#assetsTable2');
var liabilitiesTable1 = $('#liabilitiesTable1');
var liabilitiesTable2 = $('#liabilitiesTable2');
var shareholderTable = $('#shareholderTable');
// note not all subtotals are shown
$("#A2Row1").hide();
$("#A2Row2").hide();
$("#L2Row1").hide();
$("#L2Row2").hide();
console.log(window.assetsTable1);
});
// etc
そして2ページ目から、
<script type="text/javascript" src="templates/footer.js"></script>
<script type="text/javascript" src="script/jquery-1.8.1.js"></script>
<script type="text/javascript" src="script/scripts.js"></script>
<script>
$(document).ready(function() {
var vocRevTableRef = $('#vocationalRevenueTable');
var nonVocRevTableRef = $('#nonVocationalRevenueTable');
var otherRevTableRef = $('#otherRevenueTable');
// note not all subtotals are shown initially
$("#vocationalRevenueTableSub").hide();
$("#nonVocationalRevenueTableSub").hide();
$("#otherRevenueTableSub").hide();
console.log(window.vocRevTableRef);
});
// etc
Firebug では、ページ 1 での console.log() 呼び出しは非常に妥当な表示になります。
<table id="assetsTable1" class="tableWrapDataClass" width="100%">
ただし、2ページ目には戻ります
undefined
しかし、両方のページで console.log() 呼び出しを修正して、「ウィンドウ」を削除すると。ビット、例えば;
console.log(assetsTable1);
と
console.log(vocRevTableRef);
物事は正気に戻ります。どちらの場合も、Firebug はオブジェクトを表示します
Object[table#vocRevTableRef.tableWrapDataClass]
と
Object[table#assetsTable1.tableWrapDataClass]
window オブジェクトで何かが起こっています。もちろん、これは完全に腹立たしいことです。何が欠けている可能性がありますか?これをデバッグするには何を探す必要がありますか? (HTML の形式が間違っているようには見えません。)問題のオブジェクト参照を thePassedReference.tbodies から行を取り出して合計する関数に渡そうとしているだけですが、不思議なことに 2 ページ目ではもちろん失敗します。未定義の値を渡します。ハーフ!ありがとう。