.append导致IE错误

Dav*_*ard 2 jquery append

我有以下代码,在FF中工作正常,但.append()函数s在IE中发生错误.是否有人能够告诉我我的代码是否有任何问题,或者这是否是IE问题?

目的是为表单添加一个隐藏字段(根据用户点击的内容而不同),然后我提交表单.

$(function(){

    $('a.js-make-profile-image').click(function(){
        $('.append-here').append('<input type="hidden" name="action-type" value="profile-image" />');
        document.forms['attachment-action-form'].submit();
    });

});
Run Code Online (Sandbox Code Playgroud)

IE调试器给出了错误Unexpected call to method or property access,调试器在jQuery中强调了这个文本 - this.nodeType===1&&this.appendChild(a).

fca*_*ran 5

1)你有一个额外的 ;

$('a.js-make-profile-image').click(function(){;
Run Code Online (Sandbox Code Playgroud)

在这一行的最后.
如果这不能解决您的问题,请使用IE报告的错误更新您的问题

2)我认为由于name属性的价值,您也可能会发生冲突.

你有一个type属性和name="type":
因为你通常也可以通过<element>.<name>究竟<input>.type应该返回的DOM元素访问它?元素type属性值或对DOM的输入元素的引用?

所以尝试更改name属性值

3)如果没有任何改变,只是尝试更改代码

$('.append-here').append('<input type="hidden" name="type" 
                           value="profile-image" />');
Run Code Online (Sandbox Code Playgroud)

在

$('<input />').attr({
    "type"  : "hidden",
    "name"  : "action-type",
    "value" : "profile-image"
}).appendTo($('.append-here'));
Run Code Online (Sandbox Code Playgroud)

并且,正如您所发现的,请确保该元素append-here不是空元素.