簡體   English   中英

使用參數從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.
}

pluginName是“ 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是什么)。

似乎您想在元素li上觸發事件綁定。

也許您可以這樣嘗試:

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

要么:

$('.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