如何使用JQ为IE创建对象标记

How to create object tag for IE with JQ?

本文关键字:创建对象 IE 何使用 JQ      更新时间:2023-09-26

我需要将<object>标记添加到HTML中。它在所有浏览器中都能正常工作,除了IE,它会抛出很多错误,比如:

  • SyntaxError:应为"]"
  • 错误:参数无效
  • TypeError:"currentStyle"为null或不是对象(这是我尝试仅创建不带参数的纯<object>时)

我的代码是:

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之外,还有什么解决方案可以添加这个吗?

我刚刚复制粘贴了您的代码,只做了一些更改。它没有抛出任何错误。

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。