在 GWT 中获取 <div> 个没有 id 的元素
Get <div> elements without id in GWT
如果我有 html 喜欢 this.Is 有一种方法可以在 < div class="a" > 之间获取文本苹果并通过 ajax 到 gwt 应用程序?
<div class="A">
<div class="B">
<img class="icon" src="/images/ico.png" alt="" />
<div class="a">apple</div>
<div class="b">bannana</div>
</div>
</div>
我有 JavaScript 这样的:
$function(){
$('.B .icon').click(function(){
$(this).closest('.B').addClass('marked');
});
}
如果我有足够的声誉,我会将其添加为评论,因为我对您的结构和一般问题感到困惑。抱歉,如果我理解不正确,但是如果您通常将 DOM 结构遍历到您的父级,您可以使用 find 来获取元素吗? .html() 将获取所述元素的当前内容。
$(function() {
$('.icon').click(function(){
var html = $(this).closest('.B').find('div.a').html();
// Do what you want with the contents. Simple alert as example.
alert(html);
});
});
这应该能找到您要找的东西。如果您觉得符合您的要求,请标记为答案。
如果您的元素始终按照您发布的顺序排列并且不需要进一步搜索祖先元素,我建议使用 .parent() 而不是 .closest('.B') 。
如果我有 html 喜欢 this.Is 有一种方法可以在 < div class="a" > 之间获取文本苹果并通过 ajax 到 gwt 应用程序?
<div class="A">
<div class="B">
<img class="icon" src="/images/ico.png" alt="" />
<div class="a">apple</div>
<div class="b">bannana</div>
</div>
</div>
我有 JavaScript 这样的:
$function(){
$('.B .icon').click(function(){
$(this).closest('.B').addClass('marked');
});
}
如果我有足够的声誉,我会将其添加为评论,因为我对您的结构和一般问题感到困惑。抱歉,如果我理解不正确,但是如果您通常将 DOM 结构遍历到您的父级,您可以使用 find 来获取元素吗? .html() 将获取所述元素的当前内容。
$(function() {
$('.icon').click(function(){
var html = $(this).closest('.B').find('div.a').html();
// Do what you want with the contents. Simple alert as example.
alert(html);
});
});
这应该能找到您要找的东西。如果您觉得符合您的要求,请标记为答案。
如果您的元素始终按照您发布的顺序排列并且不需要进一步搜索祖先元素,我建议使用 .parent() 而不是 .closest('.B') 。