如何将 jquery 转换为 javascript?

发布于 2024-09-27 11:29:23 字数 215 浏览 0 评论 0原文

我想把

$('#hidden-data').find('#' + $(this).attr('id')).html(currdata);
var hiddata = $('#hidden-data').find('#' + $(this).attr('id')).html();

它翻译成 JavaScript,但我的大脑已经融化了。 请帮忙;p

I have

$('#hidden-data').find('#' + $(this).attr('id')).html(currdata);
var hiddata = $('#hidden-data').find('#' + $(this).attr('id')).html();

I want to translate this to javascript but my brain is melted.
Please help ;p

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

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

发布评论

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

评论(2

心舞飞扬 2024-10-04 11:29:23

最简单的版本,考虑到 ID 应该是唯一的:

var hiddata = this.innerHTML = currdata;

考虑到 ID 唯一性的缩短的 jQuery 版本使这一点更加明显:

$(this).html(currdata);
var hiddata = $(this).html();

因为您从 this 获取 id 属性并且 other 元素不应该具有该 ID,只需使用 this,无需在 DOM 中查找其他任何内容...您应该已经拥有该元素。

The simplest version, given that IDs should be unique:

var hiddata = this.innerHTML = currdata;

The shortened jQuery version accounting for ID uniqueness makes this a bit more apparent:

$(this).html(currdata);
var hiddata = $(this).html();

Since you're taking the id attribute from this and no other element should have that ID, just use this, no need to find anything else in the DOM...you should already have the element.

小糖芽 2024-10-04 11:29:23
var o = document.getElementById(thisid);
o.innerHTML = currdata;
var hiddata = o.innerHTML;
var o = document.getElementById(thisid);
o.innerHTML = currdata;
var hiddata = o.innerHTML;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文