0

我需要将<object>标签添加到 HTML。它在除 IE 之外的所有浏览器中都能正常工作,这会引发很多错误,例如:

  • 语法错误:应为 ']'
  • 错误:参数无效。
  • 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 之外,是否有任何解决方案可以添加此内容?

4

1 回答 1

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");

请看我给定的小提琴。我使用的是 IE 9。

于 2013-06-26T08:37:33.143 回答