gpt4 book ai didi

jquery - 元素内第一个元素的目标内容

转载 作者:行者123 更新时间:2023-12-01 05:43:52 25 4
gpt4 key购买 nike

关于mouseover() ,我的目标列表元素 #hello 。在该列表项中,第一个元素是一个没有 ID 的标签,请参阅:

<li id="hello">
<a href="#">0</a>
<div...
</li>

我想返回 <a> 内的数据标签。我该怎么做?

jQuery( document ).on( 'mouseover', '#hello', function() {
jQuery.ajax({
// code condensed
success:function(data){

// how do I target the A tag?
jQuery(this).next().html(data);

}
});
});

最佳答案

尝试利用jQuery.ajax( url [, settings ] )上下文

jQuery( document ).on( 'mouseover', '#hello', function(e) {
jQuery.ajax({
// code condensed
context: jQuery(e.target).parent().find("a:eq(0)"), // `this` at `success`
success:function(data){
// how do I target the A tag?
jQuery(this).html(data); // `this` : `#hello > a:eq(0)`
}
});
});

jQuery( document ).on( 'mouseover', '#hello', function(e) {
jQuery.ajax({
// code condensed
url:"https://gist.githubusercontent.com/guest271314/6a76aa9d2921350c9d53/raw/49fbc054731540fa68b565e398d3574fde7366e9/abc.txt",
type:"GET",
context: jQuery(e.target).parent().find("a:eq(0)"),
success:function(data){
// how do I target the A tag?
jQuery(this).html(data);

}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<li id="hello">
<a href="#">0</a>
<div>...</div>
</li>

关于jquery - 元素内第一个元素的目标内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28769525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com