jQuery - 无法更改 IE 中克隆表单的 id

发布于 2024-10-04 18:12:47 字数 501 浏览 1 评论 0原文

我想动态地将行添加到表中,我通过克隆行并更改其 id 来实现:

var 克隆 = $('#tempRow').clone().attr("id","tr" + trLastId);

然后我想更改该行中其他组件的id,例如:

clone.find('input[id^="upload"]').attr("id","upload" + trLastId);

时,就会出现问题:

当我想要更改表单的 id(该表单是该行的第一个子级并包含所有其他组件) cloned.find("form").attr('id', "dynamicForm"+trLastId);

上面的所有行在 Firefox 中都可以正常工作,但最后一行在 IE8 中不起作用。克隆尚未插入(在插入之前我需要更改所有 id),只是保存到“克隆”变量中。为什么 IE 不允许我更改克隆表单的 id?我怎样才能克服它?我正在使用jquery 1.3.2。

I want to dynamically add rows to the table, what I achieve by cloning the row and changing its id:


var cloned = $('#tempRow').clone().attr("id","tr" + trLastId);

Then I want to change the ids of other components in the row, e.g.:


cloned.find('input[id^="upload"]').attr("id","upload" + trLastId);

The problem arises when I want to change the id of the form, which is the first child of the row and contains all the other components:


cloned.find("form").attr('id', "dynamicForm"+trLastId);

All the lines above work fine in Firefox but the last line does not work in IE8. The clone is not inserted yet(before inserting it I need to change all the ids), just saved into 'cloned' variable. Why IE doesn't allow me to change the id of cloned form? How can I overcome it? I'm using jquery 1.3.2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2024-10-11 18:12:47

您的描述表明您的 HTML 不是 100% 有效,例如

...

<表单>...。 JavaScript 需要在有效的 DOM 树中工作,因此当浏览器发现无效的 HTML 时,它会尝试更改结构以使其有效。这意味着 jQuery 正在处理的实际文档可能与您想象的不同;它甚至可能因浏览器而异。

您能否确认您的 HTML 是否在 http://validator.w3.org/ 或任何其他类似服务上验证?

Your description suggests that your HTML is not 100% valid, something like <tr><form>...</form></tr> or <tr><td><form></td>...<td></form></td></tr>. JavaScript needs to work in a valid DOM tree so when the browser finds invalid HTML it tries to alter the structure to make it valid. That means that the actual document jQuery is working on may be different from the one you have in mind; it may even vary across browsers.

Can you confirm whether your HTML validates at http://validator.w3.org/ or any other similar service?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文