单击按钮时如何清除标签?

时间:2018-04-13 11:40:49

标签: javascript php css wordpress

我有一个计算和显示的输入字段!但是当我想进入下一页(进行新的计算)时,我的代码只清除输入字段而不是显示de result的标签。我的代码显示在..

下面
    <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!
    });

}

1 个答案:

答案 0 :(得分:1)

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

&#13;
&#13;
    $(".o-exercise__button").on('click',function(){
        $(".o-money__answer").val(''); 
        $(".o-money__totalsum").text(''); 
    });
&#13;
<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>
&#13;
&#13;
&#13;