2

我尝试了以下示例,我的目标是实现如果我按下重置按钮,只有当前行中的字段将被重置,这是否可能只使用 html5 而没有 jquery/javascript?欢迎任何想法:)

<form action="fieldset_legend.htm">
  <fieldset>
    <legend>Absender</legend>

        <label for="vor">Ihr Vorname:</label>
        <input id="vor" size="40" maxlength="40" name="Vorname" type="text">
        <input type="reset" for="vor" value="reset">

        <label for="nach">Ihr Zuname:</label>
        <input  id="nach" size="40" maxlength="40" name="Zuname" type="text">
        <input type="reset" for="nach" value="reset">

  </fieldset>
</form>
4

2 回答 2

2

使用 javascript...

function resetInput(id) {
   document.getElementById(id+"input").value="";
}

HTML:

    <label for="vor">Ihr Vorname:</label>
    <input id="vorInput" size="40" maxlength="40" name="Vorname" type="text">
    <input type="button" id="vor" onclick="resetInput(this.id) "value="reset">

    <label for="nach">Ihr Zuname:</label>
    <input  id="nachInput" size="40" maxlength="40" name="Zuname" type="text">
    <input type="button" id="nach" onclick="resetInput(this.id) value="reset">
于 2014-06-22T13:37:29.243 回答
0

我不相信在这种情况下有办法避免 JavaScript,因为输入“reset”将为表单中的所有元素重置。

重置:将表单内容重置为默认值的按钮。

输入元素

于 2014-06-22T13:32:31.160 回答