- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="webProject.兼容非兼容.WebForm1" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title></title>
- <script type="text/javascript">
- function clk() {
- var VLCObj = document.getElementById('MyOject0');
- if ( VLCObj != null )
- {
- alert(VLCObj.data);
- VLCObj.data = "";
- }
- alert(VLCObj.data);
- var VLCObj1 = document.getElementById('myTest');
- if (VLCObj1 != null)
- {
- alert(VLCObj1.data);
- VLCObj1.data = "";
- }
- alert(VLCObj1.data);
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div id="myTest" onclick="clk()">mytest</div>
- </div>
- <object width="301" height="230" title="" id="MyOject0" classid="clsid:52c209fd-75f6-41da-893f-fbda4a1bb1b8" style="background-color: black; display: block;"/>
- </form>
- </body>
- </html>
如上代码
非兼容模式下,object元素是默认有一个data值,且为空,当我们为它赋值后,这个值会变为,当前URL.
兼容模式下,object元素是无默认data值,为undefined,当我们为它赋值后,这个值就为空.
所以在使用自定义属性时,应避免使用data之类可能为保留字的名称。
原文链接:http://www.software8.co/wzjs/Javascript/4188.html
本文通过一个示例展示了在IE8浏览器中,Object元素在兼容模式和非兼容模式下可能存在不同的行为。代码中利用JavaScript获取并修改Object元素的data属性,揭示了在两种模式下可能存在的差异,对于理解IE8的兼容性问题有一定参考价值。
1482

被折叠的 条评论
为什么被折叠?



