为什么 jQuery 选择器在这里不起作用?

Cop*_*ark -2 javascript jquery dom onclick jquery-selectors

我想知道为什么当我在创建英雄后尝试更新表格单元格时,id 的 jQuery 选择器在这里不起作用。我使用的是基本的 jQuery 选择器,但即使使用 innerHTML 它也不会执行任何操作。jQuery 选择器正在处理输入获取值函数,但之后就没有了,这对我来说毫无意义,控制台绝对没有给我任何错误。

HTML

<div class="col-4 hero">
    <h2>Votre personnage</h2>
    <div>
        <h3>Créer un nouveau personnage</h3>
        <p class="alert alert-danger" role="alert">Attention ! créer un nouveau personnage supprimera tout de l'ancien.</p>
        <label>Nom</label>
        <input type="text" id="hero_name_input" name="hero_name_input">
        <button>Créer personnage</button>
    </div>
    <div>
        <h3>Les statistiques de votre personnage</h3>
        <table>
            <tr>
                <th>Nom</th>
                <td id="Hname"></td>
            </tr>
            <tr>
                <th>Habilité</th>
                <td id="Hskill"></td>
            </tr>
            <tr>
                <th>Endurance</th>
                <td id="Hstamina"></td>
            </tr>
            <tr>
                <th>Chance</th>
                <td id="Hluck"></td>
            </tr>
        </table>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

$(document).ready(function() {

    $('.hero button').click( function create_hero() {
        let nom       = $('#hero_name_input').val(); // it works
        let habilite  = (roll_dice(1)+6);
        let endurance = (roll_dice(2)+12);
        let chance    = (roll_dice(1)+6);

        let hero = new Hero (nom, habilite, endurance, chance);
        //document.getElementById('Hname').innerHTML = hero.nom; // it works

        // not working block
        $('#Hname').html     = hero.nom;
        $('#Hskill').html    = hero.habilite.toString();
        $('#Hstamina').html   = hero.endurance.toString();
        $('#Hluck').html     = hero.chance.toString();
        // not working block
    });

    function roll_dice (dices) {
        if (dices == 1) {
            return Math.floor(Math.random()*6+1)
        }
        else {
            let d1 = Math.floor(Math.random()*6+1)
            let d2 = Math.floor(Math.random()*6+1)
            let dices_result = d1+d2;
            return dices_result;
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

Mar*_*der 5

$('#Hname').html(hero.nom);
Run Code Online (Sandbox Code Playgroud)

这是使用 jQuery.html()功能的正确方法。

jQuery html() 文档