2013-06-26 36 views
0

我需要将<object>标记添加到HTML。它可以在所有的浏览器罚款除了IE以外,它抛出了很多类似的错误:如何使用JQ为IE创建对象标签?

  • 语法错误:应为“]”
  • 错误:无效的参数。
  • 类型错误:“currentStyle”为空或不是一个对象(这是当我尝试只是普通<object>创建无PARAMS)

我的代码是:

jQuery('<object/>').attr('type', 'application/x-fb-vlc').append([ 
    jQuery('<param/>').attr({'name': 'windowless', 'value': 'true'}), 
    jQuery('<param/>').attr({'name': 'autoplay', 'value': 'true'}), 
    jQuery('<param/>').attr({'name': 'bgcolor', 'value': '#999999'}), 
    jQuery('<param/>').attr({'name': 'network-caching', 'value': '1000'}), 
    jQuery('<param/>').attr({'name': 'adjust-filter', 'value': 'true'}), 
    jQuery('<param/>').attr({'name': 'marquee-filter', 'value': 'true'}), 
    jQuery('<param/>').attr({'name': 'logo-filter', 'value': 'true'}), 
    jQuery('<param/>').attr({'name': 'native-scaling', 'value': 'true'}), 
    jQuery('<param/>').attr({ 
     'name': 'src', 
     'value': 'http://' + response.server + '&_=' + (new Date().getTime()) 
    }) 
]).appendTo(camera_div); 

我也试过其他方法如append

是否有任何解决方案来添加此除纯HTML之外?

+3

尝试把这个代码只有一行 – Cherniv

+0

@Cherniv会有怎样帮助?据我所知,数组和对象不介意多行。 – Broxzier

+0

@Broxzier yes但是explorer'html renderer有时候会介意 – Cherniv

回答

0

我刚刚复制粘贴你的代码在小提琴几乎没有变化。它没有抛出任何错误。

jQuery('<object/>').attr('type', 'application/x-fb-vlc').append([ 
jQuery('<param/>').attr({'name': 'windowless', 'value': 'true'}), 
jQuery('<param/>').attr({'name': 'autoplay', 'value': 'true'}), 
jQuery('<param/>').attr({'name': 'bgcolor', 'value': '#999999'}), 
jQuery('<param/>').attr({'name': 'network-caching', 'value': '1000'}), 
jQuery('<param/>').attr({'name': 'adjust-filter', 'value': 'true'}), 
jQuery('<param/>').attr({'name': 'marquee-filter', 'value': 'true'}), 
jQuery('<param/>').attr({'name': 'logo-filter', 'value': 'true'}), 
jQuery('<param/>').attr({'name': 'native-scaling', 'value': 'true'}), 
jQuery('<param/>').attr({ 
    'name': 'src', 
    'value': '' 
}) 
]).appendTo("#camera_div"); 

请看看我给出Fiddle。我正在使用IE 9