如何将父元素的属性设置为子元素的属性?

发布于 2024-08-12 01:35:09 字数 374 浏览 2 评论 0原文

我认为这应该是一件相当简单的事情,但我完全挂在这里!我真的不知道我能在这里描述多少,标题几乎解释了一切。这是一个相当奇怪的情况,因为我的谷歌技能完全失败了,而且我知道解决方案可能如此易于实施。

有人愿意向我解释一下吗?谢谢。

编辑:

好吧,没关系,显然 IE(出于兼容性原因我正在测试它)没有正确执行某些操作。我使用了正确的方法来做到这一点,但它没有发生。但你会发现,只要我在 Firefox 中打开它,它就可以工作了。

我今天学到的教训: Internet Explorer 很糟糕!

另外,非常感谢那些提供帮助的人...(我不知道解决这个词在这里是否正确)我诊断了这个问题。谢谢!

I think this should be a rather simple thing to do, but I'm completely hangin' here! I'm really not sure how much more descriptive I can be here, the title pretty much explains it all. It's a fairly odd situation because my google skills have completely failed me, and I know the solution is probably so simple to implement.

Would anyone care to explain this to me? Thanks.

EDIT:

Okay, never mind, apparently IE (which I'm testing in for compatibility reasons) doesn't do something correctly. I was using the correct method to do it, it just wasn't happening. But low-and-behold, as soon as I open it in Firefox it works.

Lesson I have learned today: Internet Explorer sucks!

Also, much kudos to those who helped... (I don't know if solve is the right word here) me diagnose this issue. Thanks!

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

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

发布评论

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

评论(2

甜味拾荒者 2024-08-19 01:35:09

未经测试,但应该大致类似于此:

var c = $('#child');
c.attr('title',c.parent().attr('title'));

Not tested, but should roughly resemble this one:

var c = $('#child');
c.attr('title',c.parent().attr('title'));
在梵高的星空下 2024-08-19 01:35:09

一步一步:

var $myElement = $('myElementSelector');      // get your element
var attrValue = $myElement.attr('someAttr');  // get the value of element's attribute
var $parent = $myElement.parent();            // get the element's parent element
$parent.attr('someAttr', attrValue);          // set parent's attribute to child's value 

最后三行可以更简洁地表达:

$myElement.parent().attr('someAttribute', $myElement.attr('someAttribute'););

Step by step:

var $myElement = $('myElementSelector');      // get your element
var attrValue = $myElement.attr('someAttr');  // get the value of element's attribute
var $parent = $myElement.parent();            // get the element's parent element
$parent.attr('someAttr', attrValue);          // set parent's attribute to child's value 

The last three lines could be expressed more succinctly:

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