单击按钮时如何清除标签



我有计算并显示在 !但是当我想转到下一页(进行新计算(时,我的代码只会清除输入字段,而不会清除显示 de 结果的标签。我拥有的代码显示在下面。

    <td>
    <label class="o-money__totalsum" type="number" onfocus="this.value=''" step="1" name="total-<?php echo $counter;?>" id="total-<?php echo $counter;?>">0 SEK
    </label>
    </td>
    function resetFields(){
    $("o-exercise__button").click(function(){
        $(".o-money__answer").val(''); <- my inputfields
        $(".o-money__totalsum").val(''); <- the label!
    });
}

使用.text()清除它,如注释中提到的.val()是值属性,在下面的代码片段中,我使用了一个onclick事件来触发它

    $(".o-exercise__button").on('click',function(){
        $(".o-money__answer").val(''); 
        $(".o-money__totalsum").text(''); 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td>
<label class="o-money__totalsum" type="number" onfocus="this.value=''" step="1" name="total-<?php echo $counter;?>" id="total-<?php echo $counter;?>">0 SEK
</label>
<button class="o-exercise__button">Click</button>
</td>

最新更新