IE8兼容模式与非兼容式的Object元素新发现

来源:互联网 发布:包装设计用什么软件 编辑:程序博客网 时间:2024/06/03 11:35
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="webProject.兼容非兼容.WebForm1" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml" >
  5. <head runat="server">
  6.     <title></title>
  7.         <script type="text/javascript">
  8.     function clk() {
  9.         var VLCObj = document.getElementById('MyOject0');
  10.         if ( VLCObj != null )
  11.         {
  12.             alert(VLCObj.data);
  13.             VLCObj.data = "";
  14.         }
  15.         alert(VLCObj.data);
  16.  
  17.         var VLCObj1 = document.getElementById('myTest');
  18.         if (VLCObj1 != null)
  19.         {
  20.             alert(VLCObj1.data);
  21.             VLCObj1.data = "";
  22.         }
  23.         alert(VLCObj1.data);
  24.     }
  25.         </script>
  26. </head>
  27. <body>
  28.     <form id="form1" runat="server">
  29.     <div>
  30.     <div id="myTest" onclick="clk()">mytest</div>
  31.     </div>
  32. <object width="301" height="230" title="" id="MyOject0" classid="clsid:52c209fd-75f6-41da-893f-fbda4a1bb1b8" style="background-color: black; display: block;"/>
  33.     </form>
  34. </body>
  35. </html>
如上代码
非兼容模式下,object元素是默认有一个data值,且为空,当我们为它赋值后,这个值会变为,当前URL.
兼容模式下,object元素是无默认data值,为undefined,当我们为它赋值后,这个值就为空.
 
所以在使用自定义属性时,应避免使用data之类可能为保留字的名称。
原文链接:http://www.software8.co/wzjs/Javascript/4188.html
原创粉丝点击