jQueryフォームの検証を行っていますが、問題が発生しました。これまでのところ、次のコードがあります。
// catch any form submission
$('form').submit(function () {
'use strict';
// if the browser doesn't support HTML5's required attribute
if (!Modernizr.input.required) {
// catch any field that should be required
$(this).find('input[required]').each(function () {
// if is empty
if ($(this).val() === '') {
// create a span that contains a warning to the user
var requiredFieldWarning = document.createElement('span');
requiredFieldWarning.text = 'This field is required.';
// display the span next to the current field
}
});
}
});
span
送信されたフォームの検証されない入力の横に「添付」または表示しようとしていますが、方法がわかりません。私は目立たないようにこれを行いたいので、span
JavaScript 内で上記を作成します。
また、送信されたフォームのいずれかのフィールドが検証されない場合、フォームが送信されないようにするにはどうすればよいですか?