Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery复杂度获取属性_Javascript_Jquery - Fatal编程技术网

Javascript 使用jQuery复杂度获取属性

Javascript 使用jQuery复杂度获取属性,javascript,jquery,Javascript,Jquery,我试图获取另一个标记中的images alt属性,但问题是我到处都有类似的图像。我可以访问这些图像的唯一方法是使用这个关键字 jQuery(".content p").mouseenter(function () { var temp = jQuery(this+' img').attr('alt'); jQuery(this).append("<span>shit men</span>"); }); jQuery(“.content p”).mouse

我试图获取另一个标记中的images alt属性,但问题是我到处都有类似的图像。我可以访问这些图像的唯一方法是使用
这个
关键字

jQuery(".content p").mouseenter(function () {
    var temp = jQuery(this+' img').attr('alt');
    jQuery(this).append("<span>shit men</span>");
});
jQuery(“.content p”).mouseenter(函数(){
var temp=jQuery(this+'img').attr('alt');
jQuery(this).append(“狗屎男人”);
});
HTML



通过使用
我只能访问
标签,但我想通过
关键字访问
标签,而上述代码不起作用。我的问题是,是否可以将标记连接到
例如
此+'img'

基本上,您需要在所选元素中获取
img
,因此只需找到它即可

jQuery(".content p").mouseenter(function () {
    var temp = jQuery(this).find('img').attr('alt');
    jQuery(this).append("<span>shit men</span>");
});
jQuery(“.content p”).mouseenter(函数(){
var temp=jQuery(this.find('img').attr('alt');
jQuery(this).append(“狗屎男人”);
});

$('img',this).attr('alt')
adeneo->好吧,你应该把这个写在答案中,而不是评论中。但谢谢,它是有效的。请提供一个解释,而不仅仅是代码。很明显,OP是一个初学者,所以你解释得越多,你的答案就越有帮助。我是新来的,但感谢adaneo用简短的代码回答了问题。但答案上没有。
jQuery(".content p").mouseenter(function () {
    var temp = jQuery(this).find('img').attr('alt');
    jQuery(this).append("<span>shit men</span>");
});
$('img', this).attr('alt');  // source from adeneo