从 JQuery 带参数调用 onclick 函数
Call the onclick function from JQuery with parameters
我正在为我的网站使用 http://www.bjornblog.com/web/jquery-store-locator-plugin 的商店定位器 jquery 插件,一切正常,但我想添加的是一旦生成商店位置列表,第一个在列表被自动点击。
在 Jquery 中,我可以看到有一个部分控制列表上的点击。它有一些参数。
// Handle clicks from the list
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
插件名称是 'storelocator' 并且 _this.settings.locationList 是 'bh-sl-loc-list'
html
上显示的列表元素
<div class="bh-sl-loc-list">
<ul class="list list-unstyled"></ul>
<li></li>
<li></li>
<li></li>
</div>
我尝试了下面的方法,但显然没有任何效果,我应该使用什么样的语法来传递参数并调用它?非常感谢。
document.getElementById(".bh-sl-loc-list:first-child").onclick();
$('.bh-sl-loc-list:first-child').trigger('click');
事件绑定有一个命名空间,您需要将其包含在您的 trigger
调用中。
$('.bh-sl-loc-list:first-child').trigger('click.pluginName');
将 pluginName
替换为插件的实际名称(无论其内部变量 pluginName
中的什么)。
$(document).on('click' , pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
试试这个:
document.getElementById("bh-sl-loc-list:first-child").click();
看来你是想触发元素li的事件绑定
也许你可以这样尝试:
$('.bh-sl-loc-list li:first-child').trigger('click.pluginName');
或者:
$('.bh-sl-loc-list ul li:first-child').trigger('click.pluginName');
我正在为我的网站使用 http://www.bjornblog.com/web/jquery-store-locator-plugin 的商店定位器 jquery 插件,一切正常,但我想添加的是一旦生成商店位置列表,第一个在列表被自动点击。
在 Jquery 中,我可以看到有一个部分控制列表上的点击。它有一些参数。
// Handle clicks from the list
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
插件名称是 'storelocator' 并且 _this.settings.locationList 是 'bh-sl-loc-list'
html
上显示的列表元素<div class="bh-sl-loc-list">
<ul class="list list-unstyled"></ul>
<li></li>
<li></li>
<li></li>
</div>
我尝试了下面的方法,但显然没有任何效果,我应该使用什么样的语法来传递参数并调用它?非常感谢。
document.getElementById(".bh-sl-loc-list:first-child").onclick();
$('.bh-sl-loc-list:first-child').trigger('click');
事件绑定有一个命名空间,您需要将其包含在您的 trigger
调用中。
$('.bh-sl-loc-list:first-child').trigger('click.pluginName');
将 pluginName
替换为插件的实际名称(无论其内部变量 pluginName
中的什么)。
$(document).on('click' , pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
试试这个:
document.getElementById("bh-sl-loc-list:first-child").click();
看来你是想触发元素li的事件绑定
也许你可以这样尝试:
$('.bh-sl-loc-list li:first-child').trigger('click.pluginName');
或者:
$('.bh-sl-loc-list ul li:first-child').trigger('click.pluginName');