动态VML元素创建

时间:2013-08-23 06:08:29

标签: javascript jquery html internet-explorer vml

我正在动态创建VML元素。请参考下面的代码。

<html> 
<head>  
<!-- VML requires VML namespace and behavior. --> 
 <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
<script type="text/javascript">
    //Flag to stop rectangle from spinning. 
    var spin;
    $(document).ready(function () {
        document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', "#default#VML");
        // Create element in memory. 
        var r = document.createElement("v:rect");
        // Define width, height, color, and unique ID.
        $(r).css("width", "100");
        $(r).css("height", "100");
        $(r).attr("fillcolor", "blue");
        $(r).attr("strokecolor", "red");
        $(r).attr("strokeweight", "5");
        $(r).css('left', '100');
        $(r).css('top', '100');
        $(r).css('position', 'absolute');
        $(r).css('opacity', '0.2');
        r.id = "myRect";
        // Attach rectangle to the document at the  the specified Div. 
        anchorDiv.appendChild(r);

    });

</script>  
</head>  
<body>  

<div id="anchorDiv"></div>  
</body> 
</html> 

浏览器模式显示输出 - &gt; IE 7和文档模式 - &gt; IE 5 。请参考下图。

enter image description here

但在更改文档模式后 - > IE 7 没有显示任何内容(即空白屏幕)。然后我在IE浏览器的开发者工具中点击了两次编辑按钮。请参考下图

enter image description here

显示矩形。我不知道这是什么原因?有时甚至在IE 5文档模式本身矩形不显示然后我按照相同的程序(在IE浏览器的开发者工具中点击两次编辑按钮),它将显示矩形。有人可以解释一下这会出现什么问题吗?

谢谢,

希瓦

0 个答案:

没有答案
相关问题