我有这个HTML
<div class="gallery_images" id="10">
<a href="" data-toggle="modal" data-target="#myModal9" tabindex="0">
<img class="img-fluid" src="http://contest.geojidesign.com/wp-content/uploads/contest_entries/thumbnail-1680__1050__auto___wp-content_uploads_2015_01_ajax-forms.jpg">
</a>
</div>
使用jquery我想从页面url获取图像链接,如果与html中的图像url匹配,则触发作为锚标记的图像父图像上的点击事件。
答案 0 :(得分:0)
使用URLSearchParams
获取url参数和trigger
事件以触发点击。
var searchParams = new URLSearchParams(window.location.search)
var param = '';
if(searchParams.has('img')) // true
{
param = searchParams.get('img')
}
var imgSrc = $('.img-fluid').attr('src');
if (param==imgSrc)
{
$( '.img-fluid' ).parent().trigger( "click" );
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="gallery_images" id="10">
<a href="" data-toggle="modal" data-target="#myModal9" tabindex="0">
<img class="img-fluid" src="http://contest.geojidesign.com/wp-content/uploads/contest_entries/thumbnail-1680__1050__auto___wp-content_uploads_2015_01_ajax-forms.jpg">
</a>
</div>
&#13;