0

昨日からいくつかのことを試しましたが、目標を達成できません。

アイデアは次のとおりです。

文字「Div」をクリックすると、私のウェブサイト内のパラメーターを変更するための小さなメニューが表示されます。問題は、「クラスピッカー」を削除したいのですが、うまくいきません。

var CharacterClasses = [
    { id: 1, name: 'Warrior', cssClass: 'warrior'},
    { id: 2, name: 'Paladin', cssClass: 'paladin'},
    ...
]

$('.group_miniature').click( function(){

    // Removing all existant class choices
    $(".group-panel_class_picker").remove()

    // Creating the class picker
    var Panel = $("<div id=\"panel_class_picker\"></div>").addClass('group-panel_class_picker')

    // Append the whole thing
    $(this).append(Panel)

    // Iterating each class to add a div
    CharacterClasses.forEach( function(item){

        // Creating the div
        let btn_class = $("<div>&nbsp</div>").addClass( [item.cssClass,'group-btn_class'] )

        Panel.append(btn_class)

        Panel.on("click", ".group-btn_class", function(event){
            $(this).parent().remove() // This is my problem, it does not remove the parent
            console.log('Click :)') // This appears in my console
        })

    })   

})
4

1 に答える 1

0
Panel.on("click", ".group-btn_class", function(event){
            $(this).parent().hide()
            event.stopPropagation()
            console.log('Click criss')
        })

event.stopPropagation() を追加する必要があることがわかりました

今では問題なく動作します!:)

于 2022-02-06T16:22:52.670 に答える