0

私は JS コンソールを調べていて、いくつかの小さな問題を修正するのに役立ちましたが、この警告が真剣に心配する必要があるかどうか知りたいですか?

これはエラーを与えるコードです:

<script type="text/javascript"
src="https://www.safaviehhome.com/product_images/locations/js/jqgalscroll.js"></script>
<script src="https://www.safaviehhome.com/product_images/mainnav/stuHover.js"             type="text/javascript"></script>
<script>
function layerSetup(id,visibility){
if(document.getElementById){
this.obj = document.getElementById(id).style;
Uncaught TypeError: Cannot read property 'style' of null
Uncaught TypeError: Cannot read property 'style' of null
<!--Includes many more of the same "Cannot read property 'style' of null messages -->

this.obj.visibility = visibility;
return this.obj;}
else if(document.all){
this.obj = document.all[id].style;
this.obj.visibility = visibility;
return this.obj;}
else if(document.layers){
this.obj = document.layers[id];
this.obj.visibility = visibility;
return this.obj;}
}
function visVisible(param){
new layerSetup(param,'visible');
}

function visHidden(param){
new layerSetup(param,'hidden');
}</script>

ラグのカテゴリが正常に機能しているため、なぜこれが起こっているのか、心配する必要があるのか​​ どうかはわかりません. 誰でも洞察を提供できますか?私自身の説明を提供していないことをお詫びしますが、以前の同僚が書いたこの JS は私が書いたものではありません。彼が犯したすべての間違いをデバッグするのは私次第です。それは学習プロセスですが、私はまだこれに少し慣れていません..

4

2 に答える 2

2

これには 2 つの理由が考えられます。

  1. ページのどこかで、パラメーターの 1 つとしてlayerSetup関数が呼び出されてnullいます。
  2. 関数に渡された ID を持つ要素がlayerSetupページに存在しません。

Chrome デベロッパー コンソールPause on All Exceptionsでは、左下のバーにある一時停止記号の付いたボタンをクリックできます。これは、関数に渡されるパラメーターが何であるかを判断するのに役立ちます。

于 2012-06-04T19:50:13.553 に答える
0

document.all を避ける

http://www.javascripttoolbox.com/bestpractices/

http://simonwillison.net/2003/Aug/11/documentAll/

于 2012-06-04T19:49:32.943 に答える