Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在IE7中动态注册VML行为_Javascript_Internet Explorer 7_Drawing_Shapes_Vml - Fatal编程技术网

Javascript 在IE7中动态注册VML行为

Javascript 在IE7中动态注册VML行为,javascript,internet-explorer-7,drawing,shapes,vml,Javascript,Internet Explorer 7,Drawing,Shapes,Vml,我正在尝试在IE7中绘制一些形状,并尝试完全使用JavaScript来完成。首先,我像这样注册v名称空间 document.getElementsByTagName('html')[0].setAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); 我可以看出它是正确添加的。然后我尝试添加一个style元素,并将元素的VML行为如下所示: var vstyle = document.createElement('style'); vstyl

我正在尝试在IE7中绘制一些形状,并尝试完全使用JavaScript来完成。首先,我像这样注册v名称空间

document.getElementsByTagName('html')[0].setAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
我可以看出它是正确添加的。然后我尝试添加一个style元素,并将元素的VML行为如下所示:

var vstyle = document.createElement('style');
vstyle.innerHTML = 'v\:* {behavior: url(#default#VML);}}';  // Unknown runtime error
document.getElementsByTagName('head')[0].appendChild(vstyle);

我在IE6和IE7的第二行得到一个
未知运行时错误。有什么问题吗?不支持innerHTML吗?还有其他技巧吗?

您可以使用下面的代码为VML创建样式表

document.namespaces.add("v","urn:schemas-microsoft-com:vml");
var style = document.createStyleSheet();
style.addRule('v\\:*', "behavior: url(#default#VML);");
这段代码将在IE7及以上版本中运行,但我还没有在IE6中进行测试