[英]How to grab data inside a link that has event?
我想從類似事件的事件中獲取一些數據:
<a onclick="ga('send', 'event', 'View Seller Contact', 'Alfa Romeo', '147');" style="min-width: 123px;" data-id="161795" data-click="view-seller-contact" class="btn btn-primary-blue btn-xs " href="#">View Seller Contact</a>
單擊該鏈接后將顯示數據。 我想獲取單擊鏈接后顯示的數據。 我想知道如何從這種事情中獲取數據嗎? 請任何人給我任何想法。請指導我。 謝謝你
您的意思是單擊錨標記時的屬性?
第一傳遞當前元素的引用作為this
的ga
方法
<a onclick="ga('send', 'event', 'View Seller Contact', 'Alfa Romeo', '147', this);" style="min-width: 123px;" data-id="161795" data-click="view-seller-contact" class="btn btn-primary-blue btn-xs " href="#">View Seller Contact</a>
現在在ga()
方法中,您可以執行
function ga( arg1, arg2, arg3, arg4, arg5, thisObj )
{
$(thisObj).data('id')
//rest of the code
}
如果要訪問鏈接的data-
屬性值(在data-id="161795"
和data-click="view-seller-contact"
),請使用.data()
方法。
$('a').on('click', function(){
var linkData = $(this).data();
});
linkData
變量將是一個對象- { id: 161795, click: "view-seller-contact" }
。 隨心所欲地使用它)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.