當我單擊JavaScript按鈕時,打印按鈕的對象。我在圖片中添加了這個例子。 現在我想要做的是我想獲得默認狀態下的ID 0,這是這個按鈕的子對象。零下。我如何訪問它。javascript無法訪問子對象
$("#Inplay_match_table").on("click", ".btn-favrite", function() {
var a = $(this)
, B = a.parents("tr").data("match_id")
, C = a.parents("tr");
console.log (a);
Output attached in the picture
----
console.log (a.0);
我給出錯誤。
我很抱歉,我的英語
除了'a.0'不是有效的JavaScript,它並不常見到索引到一個jQuery對象。在這種情況下,它更簡單:'a'是隻包含單個元素的jQuery對象,即'this'。所以直接訪問'this'即可。 '這個=== a [0]'。 –
不知道我是否正確理解你的問題,但如果你只是想獲得按鈕「id」屬性,你可以簡單地做:'console.log(a.attr('id'))''。 – DavidDomain
感謝您幫助您成爲最好的 –