検索
ホームページウェブフロントエンドjsチュートリアルJS IE と FF の互換性問題の概要_JavaScript スキル

1. document.form.item の問題
既存の問題:
既存のコードには document.formName.item("itemName") のようなステートメントが多数あり、MF
解決策:
代わりに document.formName.elements["elementName"] を使用します
その他
2 を参照
2. コレクション クラス オブジェクトの問題
既存の問題 :
既存のコード内の多くのコレクション クラス オブジェクトは、アクセス時に () を使用しますが、IE はそれを受け入れることができますが、MF は受け入れられません。
解決策:
添字演算として代わりに [] を使用してください。例: document.forms("formName") は document.forms["formName"] に変更されます。
別の例: document.getElementsByName("inputName")(1) が document.getElementsByName("inputName")[1] に変更されました
3. window.event
既存の問題:
MF では window.event を使用できません
解決策:
MF のイベントはイベントが発生するシーンでのみ使用でき、この問題はまだ解決できません。次のように変更できます:
元のコード (IE で実行可能):

...


新しいコード (IE および MF で実行可能) :

...

さらに、新しいコードの最初の行が変更されず、古いコードと同じである場合 (つまり、gotoSubmit呼び出しにはパラメーターが指定されていません)、IE でのみ実行できますが、エラーは発生しません。したがって、このソリューションの tpl 部分は依然として古いコードと互換性があります。
4. HTML オブジェクトの ID をオブジェクト名として使用する問題

既存の問題:
IE では、HTML オブジェクトの ID を変数として直接使用できます。ドキュメントの下位オブジェクトの名前。 MFにはありません。
解決策: オブジェクト変数として idName の代わりに getElementById("idName") を使用します。
5. idName 文字列を使用してオブジェクトを取得する場合の問題

既存の問題:
IE では、idName の ID を持つ HTML オブジェクトを取得できます。 MFはできません。
解決策: eval(idName) の代わりに getElementById(idName) を使用します。
6. 変数名が HTML のオブジェクト ID と同じである問題

既存の問題:
MF では、オブジェクト ID が HTML の名前として使用されないため、オブジェクトの場合、HTML で使用できます。 同じオブジェクト ID を持つ変数名は IE では使用できません。
解決策:
変数を宣言するときは、IE で正常に実行できるように、あいまいさを避けるために常に var を追加します。
さらに、エラーを減らすために、HTML オブジェクト ID と同じ変数名を使用しないことをお勧めします。
その他: 質問 4 を参照
7. Event.x およびevent.y の問題

既存の問題:
IE では、イベント オブジェクトには x、y 属性があります。 、MFでは利用できません。
解決策:
MF では、event.x に相当するのは、event.pageX です。ただし、event.pageX は IE では使用できません。
したがって、event.x の代わりに、event.clientX が使用されます。この変数はIEにも存在します。
Event.clientX とevent.pageX には微妙な違いがありますが (ページ全体にスクロール バーがある場合)、ほとんどの場合は同等です。
まったく同じにしたい場合は、もう少し問題があります:
mX =event.x ?event.x :event.pageX
event.x の代わりに mX を使用します。 >その他:
イベント。layerX は IE と MF の両方で使用できますが、具体的な違いがあるかどうかはまだテストされていません。 8. フレームについて

既存の問題:
IE では window.testFrame を使用してフレームを取得できますが、MF では取得できません
解決策:
フレーム内使用法における mf と ie の主な違いは次のとおりです。
次の属性がフレーム タグに記述されている場合:

その後、ie は ID または名前を通じてこのフレームに対応するウィンドウ オブジェクトにアクセスできます。
そして、mf はこのフレームに対応するウィンドウ オブジェクトに名前を通じてのみアクセスできます
たとえば、上記のフレーム タグがトップ ウィンドウ内の htm に記述されている場合、次のようにアクセスできます
つまり:このウィンドウ オブジェクトにアクセスするには、window.top.frameId または window .top.frameName を使用します
mf: このウィンドウ オブジェクトにアクセスするには、window.top.frameName のみを使用できます
さらに、window.top.document.getElementById(" FrameId" は mf と ie ") の両方で使用して、フレーム タグ
にアクセスできます。 また、window.top.document.getElementById("testFrame").src = 'xx.htm' を使用して、フレーム タグのコンテンツを切り替えることができます。 Frame
または window.top.frameName.location = 'xx.htm' を使用してフレームの内容を切り替えることができます
フレームとウィンドウの説明については、「ウィンドウとフレーム」の記事を参照してください。 bbs
と /test/js/test_frame/ ディレクトリ下のテスト
- ---adun 2004.12.09 修正
9. mf では、定義した属性は getAttribute( )

10. mf にはparentElement parement.children はありませんが、parentNode を使用します。
childNodes の添字の意味は IE と MF で異なり、空のテキスト ノードを使用します。 childNodes に挿入されます。
通常、この問題は、node.getElementsByTagName() を使用して回避できます。
HTML でノードが欠落している場合、IE と MF はparentNodeを異なる方法で解釈します。たとえば、





The value of input.parentNode in MF is form, while the value of input.parentNode in IE is an empty node.
There is no removeNode method for nodes in MF. You must use the following method node.parentNode.removeChild( node)
11.const Problems
Existing problems:
The const keyword cannot be used in IE. Such as const constVar = 32; This is a syntax error in IE.
Solution:
Do not use const, use var instead.
12. Body object
MF’s body exists before the body tag is fully read by the browser, while IE must exist after the body is fully read
13 . url encoding. If you write the url in js, just write it directly & don't write it. For example, var url = 'xx.jsp?objectName=xx&objectEvent=xxx';
frm.action = url, then it is very likely that the url will not be displayed normally. As a result, the parameters are not correctly transmitted to the server
Generally, the server will report an error that the parameter is not found
Of course, the exception is if it is in tpl, because tpl conforms to the xml specification and requires & to be written as&
General MF cannot recognize js & in
14. nodeName and tagName issues
Existing issues:
In MF, all nodes have nodeName values, but textNode has no tagName value. In IE, there seems to be a problem with the use of nodeName (the specific situation has not been tested, but my IE has died several times).
Workaround:
Use tagName but should detect if it is empty.

15. Element attributes The input.type attribute is read-only under IE, but it can be modified under MF

16. document.getElementsByName() and document.all[name ] Problem Existing problem:
In IE, neither getElementsByName() nor document.all[name] can be used to obtain div elements (I don’t know if there are other elements that cannot be obtained) .

17. Problems with DOM data islands Existing problems:
In IE, the
tag has special meaning, can contain XML DOM, and can be implemented with HTML components Data binding. In MF, is just an unknown tag. In addition, for IE, actually means that this is an ActiveX object, but it is hung in the DOM tree of HTML itself. As a node, it will have a serious impact on the traversal of the DOM tree. Solution:
IE's data binding mechanism can be simulated with JS, but it is too troublesome, so it is recommended not to use the data binding mechanism Or look for a library that implements this kind of simulation. We only discuss how to achieve DOM compatibility. In MF, both known HTML tags and other tags that comply with XML specifications are processed using a unified DOM tree. Therefore, MF can actually use DOM data islands, but the small difference from IE is that in IE
is a DOM document, while in MF it is just a DOM node. This difference is usually not a problem. But there is a small detail, In order to be compatible with the rather arbitrary syntax of HTML, MF cannot recognize abbreviated empty tags. For example: xxxx , where and is an abbreviation, which will make MF unrecognizable. It should be written as: However, I suspect that if you use XHTML, there may not be such a problem. But I haven’t tried it yet. . Regarding the problem of interfering with the DOM structure of HTML in IE, my current method is to delete it from the DOM of HTML after processing. I don’t know if there is a better solution.
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
JavaScriptのデータ型:ブラウザとNodejsに違いはありますか?JavaScriptのデータ型:ブラウザとNodejsに違いはありますか?May 14, 2025 am 12:15 AM

JavaScriptコアデータ型は、ブラウザとnode.jsで一貫していますが、余分なタイプとは異なる方法で処理されます。 1)グローバルオブジェクトはブラウザのウィンドウであり、node.jsのグローバルです2)バイナリデータの処理に使用されるNode.jsの一意のバッファオブジェクト。 3)パフォーマンスと時間の処理にも違いがあり、環境に従ってコードを調整する必要があります。

JavaScriptコメント://および / * *を使用するためのガイドJavaScriptコメント://および / * *を使用するためのガイドMay 13, 2025 pm 03:49 PM

javascriptusestwotypesofcomments:シングルライン(//)およびマルチライン(//)

Python vs. JavaScript:開発者の比較分析Python vs. JavaScript:開発者の比較分析May 09, 2025 am 12:22 AM

PythonとJavaScriptの主な違いは、タイプシステムとアプリケーションシナリオです。 1。Pythonは、科学的コンピューティングとデータ分析に適した動的タイプを使用します。 2。JavaScriptは弱いタイプを採用し、フロントエンドとフルスタックの開発で広く使用されています。この2つは、非同期プログラミングとパフォーマンスの最適化に独自の利点があり、選択する際にプロジェクトの要件に従って決定する必要があります。

Python vs. JavaScript:ジョブに適したツールを選択するPython vs. JavaScript:ジョブに適したツールを選択するMay 08, 2025 am 12:10 AM

PythonまたはJavaScriptを選択するかどうかは、プロジェクトの種類によって異なります。1)データサイエンスおよび自動化タスクのPythonを選択します。 2)フロントエンドとフルスタック開発のためにJavaScriptを選択します。 Pythonは、データ処理と自動化における強力なライブラリに好まれていますが、JavaScriptはWebインタラクションとフルスタック開発の利点に不可欠です。

PythonとJavaScript:それぞれの強みを理解するPythonとJavaScript:それぞれの強みを理解するMay 06, 2025 am 12:15 AM

PythonとJavaScriptにはそれぞれ独自の利点があり、選択はプロジェクトのニーズと個人的な好みに依存します。 1. Pythonは、データサイエンスやバックエンド開発に適した簡潔な構文を備えた学習が簡単ですが、実行速度が遅くなっています。 2。JavaScriptはフロントエンド開発のいたるところにあり、強力な非同期プログラミング機能を備えています。 node.jsはフルスタックの開発に適していますが、構文は複雑でエラーが発生しやすい場合があります。

JavaScriptのコア:CまたはCの上に構築されていますか?JavaScriptのコア:CまたはCの上に構築されていますか?May 05, 2025 am 12:07 AM

javascriptisnotbuiltoncorc;それは、解釈されていることを解釈しました。

JavaScriptアプリケーション:フロントエンドからバックエンドまでJavaScriptアプリケーション:フロントエンドからバックエンドまでMay 04, 2025 am 12:12 AM

JavaScriptは、フロントエンドおよびバックエンド開発に使用できます。フロントエンドは、DOM操作を介してユーザーエクスペリエンスを強化し、バックエンドはnode.jsを介してサーバータスクを処理することを処理します。 1.フロントエンドの例:Webページテキストのコンテンツを変更します。 2。バックエンドの例:node.jsサーバーを作成します。

Python vs. Javascript:どの言語を学ぶべきですか?Python vs. Javascript:どの言語を学ぶべきですか?May 03, 2025 am 12:10 AM

PythonまたはJavaScriptの選択は、キャリア開発、学習曲線、エコシステムに基づいている必要があります。1)キャリア開発:Pythonはデータサイエンスとバックエンド開発に適していますが、JavaScriptはフロントエンドおよびフルスタック開発に適しています。 2)学習曲線:Python構文は簡潔で初心者に適しています。 JavaScriptの構文は柔軟です。 3)エコシステム:Pythonには豊富な科学コンピューティングライブラリがあり、JavaScriptには強力なフロントエンドフレームワークがあります。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール