2
我有以下html表單:防止驗證()
<body>
<div>
<form id="callBackForm" class="custom eight form" method="post" enctype="multipart/form-data" action="thank-you.php">
<div class="callBackFormDivs">
<div style="padding:0;" class="four mobile-one columns">
<label for="name" class="left inline">Name</label>
</div>
<div class="eight mobile-three columns">
<input class="left" id="name" name="name" required type="text" />
</div>
</div>
<div class="callBackFormDivs">
<div style="padding:0;" class="four mobile-one columns">
<label for="Age" class="left inline">Age</label>
</div>
<div class="eight mobile-three columns">
<input class="left" id="Age" name="Age" required type="text" />
</div>
</div>
<div class="callBackFormDivs callBackFormButtonContainer">
<div>
<input type="submit" value="Submit" alt="Submit">
<button class="button" style="font-weight:normal; height:34px; float:right;" onClick="fnClearForm()">RESET</button>
</div>
</div>
</form>
</div>
</body>
注意的領域都必需的屬性在他們身上設置。如果用戶嘗試在不輸入任何文本的情況下提交表單,則該屬性會向用戶顯示錯誤消息。
還有就是頁面,清除田間地頭,用form.reset()
功能上的復位按鈕,如下:
function fnClearForm()
{
document.getElementById('callBackForm').reset();
}
的問題是,當表單重置時,它導致驗證火,並將錯誤消息顯示給用戶。
我該如何預防?
我知道我可以編寫一個自定義驗證器,它可以解決這個問題,但我認爲最好找到一種方法來使驗證工作正常。
我確實發現了一些相關的問題,但他們都沒有解決這個問題。
我無法想象使用別的重置以任何理由定義的形式。除非我明確不想使用按鈕控件。 –