.append造成IE浏览器错误 [英] .append causing IE error

查看:649
本文介绍了.append造成IE浏览器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,它在FF工作正常,但 .append()函数s cauding在IE错误。有没有人能告诉我,如果有什么错我的code,或者如果这是一个IE浏览器的问题?

I have the following code, which works fine in FF, but the .append() function s cauding an error in IE. Is anyone able to tell me if there is anything wrong with my code, or if this is an IE problem?

是为了一个隐藏字段添加到表单(将根据用户点击什么不一样),然后我提交表单。

The purpose is to add a hidden field to a form (will be different depending on what the user clicks), and I then submit the form.

$(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();
    });

});

IE的调试器给误差意外的调用方法或属性访问,这个文本正在被调试器中的jQuery在突出显示 - 此.nodeType === 1安培;&安培; this.appendChild(一)

The IE debugger is giving the error Unexpected call to method or property access, and this text is being hightlighted within jQuery by the debugger - this.nodeType===1&&this.appendChild(a).

推荐答案

1),你有一个额外的;

1) you have an extra ;

$('a.js-make-profile-image').click(function(){;

在该行的末尾。结果
如果不解决您的问题,请与IE报告的错误更新您的问题

at the end of this line.
if this don't solve your problem please update your question with the error reported by IE

2)我想你也可能有冲突,由于你的名称属性的值。结果

2) I think you could also have a conflict due to the value of your name attribute.

您同时拥有键入属性和 NAME =输入:结果
因为你通常可以访问DOM元素也可通过的 &LT;组件&gt;&LT;名称&gt; 的究竟是什么&LT;输入&GT; .TYPE 应该回报?元素键入属性值或参考输入元素到DOM?

You have both a type attribute and name="type":
since you can usually access to a DOM element also via <element>.<name> what exactly <input>.type should returns? The element type attribute value or a reference to the input element into the DOM?

所以要尽量改变名称属性值

3)如果一切都没有改变,但距离尝试更改code

3) if nothing has changed yet just try to change the code

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

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

和,因为你发现,要确保元素追加-此处不是一个空元素。

and, as you discovered, be sure that the element append-here is not an empty element.

这篇关于.append造成IE浏览器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆