问题描述
限时送ChatGPT账号..我有以下代码,它在 FF 中工作正常,但 .append()
函数在 IE 中导致错误.有没有人能告诉我我的代码是否有问题,或者这是否是 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 中突出显示了此文本 - this.nodeType===1&&this.appendChild(a)
.
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) 我认为您也可能因 name
属性的值而发生冲突.
2) I think you could also have a conflict due to the value of your name
attribute.
您同时拥有 type
属性和 name="type"
:
因为您通常也可以通过
访问 DOM 元素,.type
究竟应该做什么回报?元素的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?
所以尝试改变name
属性值
3) 如果什么都没有改变就试着改变代码
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'));
而且,正如您所发现的,请确保元素 append-here
不是空元素.
and, as you discovered, be sure that the element append-here
is not an empty element.
这篇关于.append 导致 IE 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论