A compatibility problem about SELECT objects in Firefox

xiaoxiao2021-03-06  51

phenomenon:

Var objopt = document.createElement ("option"); objopt.value = "value"; objopt.text = "text"; objselect.add (objopt); Last line error modified after IE6 and Firefox via var objopt = document .createElement ("option"); objopt.value = "value"; objopt.text = "text"; try {objselect.add (objopt);} catch (e) {objselect.add (Objopt, null);} http; : //www.talkaboutprogramming.com/group/comp.lang.javascript/Messages/422841.htmlon Mon, 15 Mar 2004 20:27:29 0100, Eremax Wrote: [SNIP]> IF (Document.topics.Areas.length == 1)> Document.topics.areas.Add ("Intranet", ",", False, False); [SNIP]> Well, Any Idea About The Reason Why ? A matter of syntax? Another issue>? The method, HTMLSelectElement.add (), is a Document Object Model (DOM) method. It expects two arguments. The first is a reference to the new HTMLOptionElement to insert, while the second is WHERE to INSERT ITHERE IS A VERY SERIOUS Problem I Encountered When I Was Checking The Codei Was Going To Propose and, As UsuAL, Microsoft Are The Cause. According to the DOM 1 HTML Specification, the second argument should either be a reference to the element that the new OPTION is inserted before, or null for the end of the list. According to Microsoft, it is theindex of the element that the new OPTION will be inserted before. As you can see, the two are completely incompatible (one is an object, the other is a number) .The only way around it is to catch the exception that will be thrown when the method is called with the wrong Type of argument. if Browser Supports the Dom, IT IS Quite Likey That IT WILL Support Try ... Catch, Too.The Result Of All this is: var areas = document.topics.areas;

转载请注明原文地址:https://www.9cbs.com/read-85344.html

New Post(0)