[英]How to select element inside label on input radio select
我在 Laravel 上有一个项目 8. 我试图让人们从图库中更改他们的个人资料图片。 这就是我显示所有可用图像的方式
@foreach(glob(storage_path('app/public/gallery/*.png')) as $image)
<div class="col-2 mb-3">
<label for="{{ basename($image, '.png') }}" class="w-100">
<img src="{{ url('storage/gallery/' . basename($image)) }}" width="100px" height="100px" />
<input type="radio" name="profilephoto" value="{{ url('storage/gallery/' . basename($image)) }}" id="{{ basename($image, '.png') }}" />
</label>
</div>
@endforeach
(免费 HTML)
<label for="photo1" class="w-100">
<img src="https://example.com/storage/gallery/photo1.png" width="100px" height="100px" />
<input type="radio" name="profilephoto" value="https://example.com/storage/gallery/photo1.png" id="photo1" />
</label>
<!-- ... more labels&inputs -->
我正在尝试 select 到 jQuery <img>
元素,以便我可以向它添加一些视觉效果。 这就是我正在尝试的方式:
$('input[type="radio"][name="profilephoto"]').on('change', function() {
$('label[for="' + $(this).attr('id') + '"]').find('img').addClass('border')
});
但它不起作用。 知道怎么做吗?
这是您的解决方案:
this
传递:onclick="some(this)"
some(eve) {
parent = $(eve).parent();
}
image = $(parent).find(img);
image
变量中的这个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.