3
を削除する方法:これは、カレンダー、3つのラジオボタンやチェックボックスを作成しますチェックボックスをオフにして、私はこのようになりますHTML持って検証
<div class="form-group">
<div class="input-group">
<label for="daterange-vacancy" class="input-group-addon">Van</label>
<input type="text" id="daterange-vacancy" class="form-control" name="daterange-vacancy" placeholder="dd/mm/yyyy" data-class="daterangepicker" required="required" />
<label for="daterange-vacancy" class="input-group-addon">
<span class="fa fa-calendar"></span>
</label>
</div>
</div>
<div class="form-group">
<input class="custom-radio" type="radio" id="temp" name="time" value="1" checked="checked" required/><label for="temp" class="bold-sm">Bepaalde dag(en)</label><br/>
<input class="custom-radio" type="radio" id="project" name="time" value="2" required/><label for="project" class="bold-sm">Bepaalde periode</label><br/>
<input class="custom-radio" type="radio" id="struct" name="time" value="3" required/><label for="struct" class="bold-sm">Terugkerend</label>
</div>
<div class="form-group">
<div class="input-checkbox text-left">
<input class="form-checkbox" type="checkbox" id="other" name="other" />
<label for="other">Af te spreken</label>
</div>
</div>
を。
カレンダーと3つのラジオボタンを1つに見なす必要があります。一緒に入力する必要があります。また、検証によって次のステップに進むことはできません。 唯一の例外は、チェックボックスがオンの場合です。これは、カレンダーとラジオボタンを無効にします(そして、それらのバリデーションを削除します)。もう一度チェックボックスをオフにすると、カレンダーとラジオボタンが再度必要になります。
私のJavascriptを次のようになります。
var other = document.getElementById('other');
if (other) {
other.onchange = function() {
document.getElementById('daterange-vacancy').value = "";
document.getElementById('daterange-vacancy').disabled = this.checked;
$('input[name=other]').change(function(){
if($(this).is(':checked')) {
$('input[name=time]').attr('checked',false);
}
});
}
}
問題は、チェックボックスをチェックするときにラジオボタンをオフにしないということです。そしてそれはそれの検証を削除しません。
これはそれをやりました!ありがとうございました – Dennis
なぜ、あなたは 'other'へのプレーンなjavascriptリファレンスを作成してから、同じものへのjQueryリファレンスを作成することにしましたか? – Snowmonkey
私は長年試していて、一緒に見つかったいくつかのコードを貼り付けて祈っていました...あなたの解決策ははるかにエレガントで、魅力のように機能します – Dennis