如果這是重復(fù)的,我深表歉意,但我已經(jīng)搜索了這個特定的問題,但沒有找到。假設(shè)我有 4 個段落,我想<h3>在點擊的段落下添加元素。每個段落都有相同的數(shù)據(jù)名稱屬性$(" <h3 data-price'222'>NEW ITEM</h3>").insertAfter(???);,但我已經(jīng)嘗試過不同的值 ,但我不知道括號里寫的是什么。<body> <div class="container"> <p class="clickable" data-price="5">Apple</p> <br> <p class="clickable" data-price="7">Coffee</p> <br> <p class="clickable" data-price="9">Water</p> <br> <p class="clickable" data-price="10">Pitza</p> <br> <h3></h3> <br> <button>Reset</button> </div></body>$(function () { createCeleb();})function createCeleb() { $('p.clickable').on('click', function () { var temp = $(this).attr('data-price') this.temp = temp; let on1 = $("p").find(`[data-price='${this.temp}']`) $(" <h3 data-price'222'>NEW ITEM</h3>").insertAfter(on1); });}我希望在我點擊下面的段落后將添加元素但沒有發(fā)生任何事情我希望它是動態(tài)的并且只在點擊的段落下添加這可能嗎?
如何在單擊并具有具有特定值的數(shù)據(jù)屬性的其他元素之后在列表中添加元素?
哆啦的時光機
2021-08-20 10:04:48