私はこれを止めようとしています>> http://jsfiddle.net/justmelat/8x2WX/
私のjsfiddleを見る場合は、必要なフィールドボタンをクリックして、もう一度クリックしてください。空のフィールドを追加し続けることがわかります [これはコードが要求していることです]。
これを行うためのより良い方法は何ですか? ユーザーがたまたまボタンを2回クリックした場合、またはフォームに入力して残っているものをテストしているときに、追加ではなく、検証済みのテキストの表示を再開したい. text() と html() を試しましたが、正しく動作しません。
$("#section-11,#section-12,#section-13,#section-1011").hide();
var projtype = new Array(
{value : 'Cars', sect_id : 'fieldset#section-11'},
{value : 'Planes', sect_id : 'fieldset#section-12'},
{value : 'Boats', sect_id : 'fieldset#section-13'}
);
$("select#1169").on('change',function () {
var thisVal = $(this).val();
var sect_id ="";
//$('fieldset[id!="mainSection"]').hide();
$(projtype).each(function() {
$(this.sect_id).hide();
if(this.value == thisVal) {
$(this.sect_id).show();
}
});
});
$("#btnCatchReqFlds").on('click', function() {
//$("#holdErrMsg").append(" ");
var requiredButEmpty = $("fieldset:visible").find('input[class*="-required"], select[class*="-required"]').filter(function() {
return $.trim($(this).val()) === "";
});
if (requiredButEmpty.length) {
requiredButEmpty.each(function () {
$("#holdErrMsg").append("Please fill in the " + this.name + "<br />");
});
}
return !requiredButEmpty.length;
});