此代码可以在图像点击时打开 vanillabox,但我需要为按钮点击实现此代码。我尝试过使用 click() 方法,但它不起作用。
$(document).ready(function() {
$('#test').click(function(){
$('#grouped-image-list a').vanillabox();
});
});
上面的代码将 test 定义为按钮 id..请检查下面的 html
<button id="test" name="test" value="Click1">click1</button>
<div class="double-column">
<div class="column1">
<ul id="grouped-image-list" class="link-list">
<li><a href="HD_Wallpaper/App-screen-1.png" title="Main Screen"><img src="HD_Wallpaper/App-screen-1.png" border="0" width="300" height="300"/></a></li>
<li><a href="HD_Wallpaper/App-screen-2.png" title="Screen2"><img src="HD_Wallpaper/App-screen-2.png" border="0" width="300" height="300"/></a></li>
<li><a href="HD_Wallpaper/App-screen-3.png" title="Screen3"><img src="HD_Wallpaper/App-screen-3.png" border="0" width="300" height="300"/></a></li>
</ul>
</div>
最佳答案
尝试下面
$(document).ready(function() {
$('#grouped-image-list a').vanillabox();
$('#test').click(function(){
$('#grouped-image-list').find('a:first').trigger('click');
});
});
确保您已添加 vanillabox 的 css 和 js。
关于jquery - 单击按钮/图像打开弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135585/