我有一个表格,并且取决于是否填写了文本输入,还会出现另一个。
我的HTML
<div class="col-sm-3">
<div class="form-group">
{{ Form::label('personal_extra', 'Extra (nombre):', ['class' => 'control-label']) }}
{{ Form::text('personal_extra', null, [ 'onchange' => "personal_extra();", 'class' => 'form-control', 'id' => 'personal_extra']) }}
</div>
</div>
<div class="hidden" id="personal_extra_cantidad">
<div class="col-sm-3">
<div class="form-group">
{{ Form::label('personal_extra_cantidad', 'Extra (cantidad):', ['class' => 'control-label']) }}
{{ Form::number('personal_extra_cantidad', null, ['class' => 'form-control', 'min' => '0']) }}
</div>
</div>
</div>
我的脚本
function personal_extra() {
var x = document.getElementById('personal_extra').value;
var y = document.getElementById('personal_extra_cantidad');
if (x == null) {
y.className = "hidden";
} else {
y.className = "visible";
}
}
这是正确的格式吗?我还应该做点其他事情吗?