0

我有以下 HTML:

<div>
    <img src="source.com/image.jpg" title="My Image">
</div>

在这种情况下,我想获取所有图像的标题(“我的图像”),并将此标题添加到 parent ,以便上面的示例如下所示:

<div title="My Image">
    <img src="source.com/image.jpg" title="My Image">
</div>

如果有人能推动我朝着正确的方向前进,将不胜感激!

谢谢!

4

1 回答 1

0

This is pretty much the same question as the previous one you posted. In this case you do need to save the image node to a variable so that you can read its title and set it to the parent.

YUI().use('node', function (Y) {
  var image = Y.one('img');
  image.get('parentNode').set('title', image.get('title'));
});

If you're having trouble making changes to DOM elements I'd suggest you take a little time to read a couple of articles/books that introduce you to the subject. Here are some good options:

于 2013-07-16T13:00:37.453 回答