我想對動態生成的元素的資料做一些事情,比如列印被點擊的元素的資料,我怎么做呢?
這是我的jquery代碼:
這是我的jquery代碼。
let setHistory = () => {
$('#transaction-history').empty()。
transactionHistory.forEach((o) => {
var htmlBlock = ""/span>;
htmlBlock = `<div class="btn btn-outline transaction-history-item d-flex-column justify-content-center mr-4"> `
`<img class="transaction-history-item-image card pl-2 pr-2 pt-1 pb-1 mx-auto" src=" 。 ./assets/placeholder-image.png" alt=" >`。
`<div class="transaction-history-number mt-1 mx-auto">${o.meterNumber}</div> `
`<div class="transaction-history-value mx-auto" data-value=${o.value}>Rp${o. value.toLocaleString() 。 replaceAll(',','。')}</div>`。
`</div>`;
$('#transaction-history').append(htmlBlock)。
});
}
而transactionHistory的資料看起來是這樣的:
let transactionHistory = [
{
meterNumber: "1234152322"/span>,
value: 250000.
},
{
meterNumber: "1115648463"/span>,
value: 50000, value:
}
]
基本上,我想從我點擊的卡片上獲得 meterNumber 和值,我如何實作呢?
uj5u.com熱心網友回復:
獲得所需的資料。使用
next()函式:$(document) 。 on('click', ' .transaction-history-item-image', function() { var tranNumber = $(this).next().html() 。 var tranValue = $(this)。 next().next().html()。 });
或者通過使用
parent()和find():$(document) 。 on('click', ' .transaction-history-item-image', function() { var tranNumber = $(this).parent(). find('.transaction-history-number').html()。 var tranValue = $(this).parent(). find('.transaction-history-value').html()。 });轉載請註明出處,本文鏈接:https://www.uj5u.com/net/306713.html
標籤:
上一篇:如何將選定的時間戳轉換成Firebase服務器的時間戳安卓版
下一篇:<p>基本上,我想實作的是:</p><p>用戶將看到第一個輸入,并能夠輸入他們的數字,這些數字將被自動轉換成貨幣價值。 <p>用戶將看到第一個輸入欄位,

