Home > Article > Web Front-end > JS code reports an error in ie8 that document.getElementById(...) is empty or not an object. Solution
IE8 is more strict about declaring document types, as shown in the following code.
<input type='text' name='os' value='Windows平台' style='width:100px' /> <script type="text/javascript"> function osdo(str){ document.getElementById("os").value=str; } </script> <input name="ostmp" type="radio" value="" onclick="osdo('')" />清空 <input name="ostmp" type="radio" value="Windows平台" onclick="osdo('Windows平台')" /> Windows平台 <input name="ostmp" type="radio" value="" onclick="osdo('S60v2')" />S60v2 <input name="ostmp" type="radio" value="" onclick="osdo('S60v3')" />S60v3 <input name="ostmp" type="radio" value="" onclick="osdo('CHM')" />CHM <input name="ostmp" type="radio" value="" onclick="osdo('PDF')" />PDF <input name="ostmp" type="radio" value="" onclick="osdo('PPT')" />PPT <input name="ostmp" type="radio" value="" onclick="osdo('DOC')" />WORD <input name="ostmp" type="radio" value="" onclick="osdo('EXCEL')" />EXCEL <input name="ostmp" type="radio" value="" onclick="osdo('asp')" />asp <input name="ostmp" type="radio" value="" onclick="osdo('asp+access')" />asp+access <input name="ostmp" type="radio" value="" onclick="osdo('asp+sqlserver')" />asp+sqlserver <input name="ostmp" type="radio" value="" onclick="osdo('asp+sql/access')" /> asp+sql/access <strong>php源码</strong> <input name="ostmp" type="radio" value="" onclick="osdo('php')" />php <input name="ostmp" type="radio" value="" onclick="osdo('php+mysql')" /> php+mysql<input name="ostmp" type="radio" value="" onclick="osdo('jsp')" />jsp <strong>asp.net源码</strong> <input name="ostmp" type="radio" value="" onclick="osdo('asp.net')" />asp.net <input name="ostmp" type="radio" value="" onclick="osdo('asp.net+access')" />asp.net+access <input name="ostmp" type="radio" value="" onclick="osdo('asp.net+sql')" />asp.net+sql <input name="ostmp" type="radio" value="" onclick="osdo('asp.net+sql/access')" />asp.net+sql/access
You can see that this code can run in both ie7 and ie8. We add the declaration document to the following code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
and add the above document type declaration.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 运行环境: 清空 Windows平台 S60v2 S60v3 CHM PDF PPT WORD EXCEL asp asp+access asp+sqlserver asp+sql/access php源码 php php+mysqljsp asp.net源码 asp.net asp.net+access asp.net+sql asp.net+sql/access
The solution is found when the prompt document.getElementById(...) is empty or not an object
If there is a document declaration in the page, because when using div css layout, the document is not declared. , some parts of the page are different.
You can add the following code in the head
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
Complete code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 运行环境: 清空 Windows平台 S60v2 S60v3 CHM PDF PPT WORD EXCEL asp asp+access asp+sqlserver asp+sql/access php源码 php php+mysqljsp asp.net源码 asp.net asp.net+access asp.net+sql asp.net+sql/access