如何在 if 语句中仅附加一次项目?

How to append an item in a if-statement just once?

因此,每次我单击按钮提交表单时,附加的 div 都会自行附加。我怎样才能使 div 仅附加一次?

<div class="field">
        <div class="field">
            <div id='eerr' class="errors"></div>
        </div>
</div>

if (email == '' || emailResult == false) {
    $('#eerr').append('<div class="ui basic red pointing prompt label transition visible">Please insert your email.</div></div>');
    }

顺便说一句,这是按钮:

<button style="margin-top: 7px" type="button" onclick='singup()' class="ui primary submit button login ">clickme</button>

由于这是用于表单验证,听起来您希望 #eerr 包含所有警告。您可能需要添加额外的检查和警告,因此您可以在验证开始时清除 #eerr

const $errorElm = $('#eerr');
$errorElm.empty();
if (email == '' || emailResult == false) {
    $errorElm.append('<div class="ui basic red pointing prompt label transition visible">Please insert your email.</div></div>');
}
// other validation involving $errorElm.append