简体   繁体   English

使用参数从JQuery调用onclick函数

[英]Call the onclick function from JQuery with parameters

I am using a store locator jquery plugin from http://www.bjornblog.com/web/jquery-store-locator-plugin for my website and everything works fine but what I want to add is once the store location list is generated, the first one on the list is automatically clicked. 我正在使用来自http://www.bjornblog.com/web/jquery-store-locator-plugin的商店定位器jquery插件来访问我的网站,一切正常,但是一旦生成商店位置列表,我要添加的内容就是列表中的第一个会自动单击。

In the Jquery, I can see there is a section controlling the click on the list. 在Jquery中,我可以看到有一个部分控制列表的单击。 It has some parameters. 它有一些参数。

// Handle clicks from the list          
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}

The pluginName is 'storelocator' and _this.settings.locationList is 'bh-sl-loc-list' pluginName是“ storelocator”,_this.settings.locationList是“ bh-sl-loc-list”

the elements of the list shown on the html html上显示的列表的元素

<div class="bh-sl-loc-list">
  <ul class="list list-unstyled"></ul>
    <li></li>
    <li></li>
    <li></li>   
</div>

I tried the belows but obviously nothing worked, what sort of syntax I should use to maybe pass the parameters and call it? 我尝试了以下方法,但显然没有任何效果,应该使用哪种语法来传递参数并调用它? Much appreciated. 非常感激。

document.getElementById(".bh-sl-loc-list:first-child").onclick();
$('.bh-sl-loc-list:first-child').trigger('click');

The event binding has a namespace, you need to include that in your trigger call. 事件绑定具有名称空间,您需要在trigger调用中包含该名称空间。

$('.bh-sl-loc-list:first-child').trigger('click.pluginName');

Replace pluginName with the actual name of the plugin (whatever is in its internal variable pluginName ). pluginName替换为插件的实际名称(无论其内部变量pluginName是什么)。

It seems that you want to trigger the event bind on the element li. 似乎您想在元素li上触发事件绑定。

Maybe you could try it like this: 也许您可以这样尝试:

$('.bh-sl-loc-list li:first-child').trigger('click.pluginName');

Or: 要么:

$('.bh-sl-loc-list ul li:first-child').trigger('click.pluginName');
$(document).on('click' , pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}

尝试这个 :

document.getElementById("bh-sl-loc-list:first-child").click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM