模拟 JavaScript 中 元素的点击
对于网站,我使用 jQuery supersized gallery 脚本: http://buildinternet。 com/project/supersized/slideshow/3.2/demo.html
正如您在演示中看到的,右下角有一个小箭头按钮,用于切换缩略图栏。配置文件中没有选项可以在打开站点时自动将其混合在一起。
所以我想我必须模拟点击该按钮(该按钮是托盘按钮,请参阅 HTML)。我尝试了这样的事情:
<script>
$(function() {
$('#tray-button').click();
});
</script>
但是,这似乎在我测试过的任何浏览器中都不起作用。
有什么想法吗?
for a website, i am using the jQuery supzersized gallery script: http://buildinternet.com/project/supersized/slideshow/3.2/demo.html
As you can see in the demo, in the bottom right corner there is an little arrow button that toggles a thumbnail bar. There is no option in the config files to automatically blend this in when opening the site.
So i guess i have to simulate a click on that button (the button is the tray-button, see HTML). I tried something like this:
<script>
$(function() {
$('#tray-button').click();
});
</script>
However, this doesnt seem to work in any browsers i tested.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
试试这个
Try this
我假设您想在页面加载时弹出缩略图栏
#thump-tray
。方法如下:
找到文件 supersized.shutter.js 并找到以下代码:
在其后面添加:
不要忘记在您的页面中(插件中的 demo.html),更改
为
I assume that you want to popup the thumbnail bar
#thump-tray
on page load.Here's a way to do it:
locate the file supersized.shutter.js and find this code:
After it, add:
Dont forget in your page (demo.html in the plugin), to change
to
而不是使用
你可以尝试这个女巫将在加载整个页面(图像等)后发挥你的jquery魔法
并模拟你应该使用的点击 // 应该与 $('#tray-arrow').click( 相同);
例子:
instead of using
you culd try this witch will work your jquery magic after the full page is loaded (images etc)
and to simulate a click you culd use // shuld be the same as $('#tray-arrow').click();
example:
尝试
确保此代码是在您的轮播初始化之后。
try
Make sure that this code is after your carousel is initialized.
这看起来像是触发时机的问题。该插件还会在文档加载时加载,因此当您尝试绑定事件侦听器时,元素可能尚未创建。
也许您需要在 theme._init 函数之类的地方添加监听器
http://buildinternet.com/project/supersized/docs.html#theme-init
或类似的地方。
This looks like it's a problem of timing the trigger. The plugin also loads on document load, so maybe when you try to bind the event listener the element is not created yet.
Maybe you need to add the listener in something like the theme._init function
http://buildinternet.com/project/supersized/docs.html#theme-init
or somewhere similar.
问题可能是您的插件检测点击是由用户(真正的鼠标点击)发起的,还是通过代码发起的(通过使用
$('#id').click()
方法)。如果是这样,很自然的,通过代码点击锚元素是得不到任何结果的。检查您的插件的源代码。
A problem might be that your plugin detects whether the click has been initiated by a user (real mouse click), or through code (by using
$('#id').click()
method). If so, it's natural that you can't get any result from clicking the anchor element through code.Check the source code of your plugin.