jQuery 的appendto 和append 在IE8 中不起作用?
我在使用 jQuery 的append 和appendTo 函数时遇到了一个奇怪的问题。我正在运行一个对象并根据对象属性创建元素。在我的函数中的一些地方,我使用 .append() 和 .appendTo() 方法非常好。然而在 IE8 和 IE7 中我遇到了一个奇怪的错误。当我注释掉以下行时,错误消失了: o.append(em)
有什么想法吗?
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options and all:
var o = $("<object/>");
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
var em = $('<embed/>');
for( var e in n[k]){
em.attr(e, n[k][e]);
}
o.append(em);
}
}
}
// Insert object into container:
if(destination)
o.appendTo(destination);
}
使用以下代码也得到相同的错误:
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options and all:
var o = $("<object/>").appendTo(destination);
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
//var em = $('<embed/>');
var em = "<embed ";
for( var e in n[k]){
em += e+'="'+n[k][e]+'" ';
//em.attr(e, n[k][e]);
}
em+= "></embed>";
//$("#mediaPlayer").append(em);
}
}
}
console.log(em);
$("#mediaPlayer").html(em);
}
Error attempts here in jquery (this.appendChild( elem );)
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
},
I'm encountering a weird issue using jQuery's append and appendTo function. I am running through an object and creating elements based on the objects properties. A few places in my function, I use the .append() and .appendTo() methods perfectly fine. However in IE8 and IE7 i get a weird error. The error disappears when I comment out the line: o.append(em)
Any ideas?
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options and all:
var o = $("<object/>");
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
var em = $('<embed/>');
for( var e in n[k]){
em.attr(e, n[k][e]);
}
o.append(em);
}
}
}
// Insert object into container:
if(destination)
o.appendTo(destination);
}
Getting the same exact error with the following code too:
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options and all:
var o = $("<object/>").appendTo(destination);
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
//var em = $('<embed/>');
var em = "<embed ";
for( var e in n[k]){
em += e+'="'+n[k][e]+'" ';
//em.attr(e, n[k][e]);
}
em+= "></embed>";
//$("#mediaPlayer").append(em);
}
}
}
console.log(em);
$("#mediaPlayer").html(em);
}
Error happens here in jquery (this.appendChild( elem );)
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在最后将“o”附加到目标中,而是在代码中尝试这样做。我认为这会起作用。
并评论这一行
Instead of appending "o" into destination at the end try this in your code. I think this will work.
and comment this lines
只需使用 jquery 的 .html() 函数即可。
用于填充
,例如:
Just use .html() function of jquery.
For populating
<ul id="List"></ul>
, for example: