如果选中了复选框,我需要启用或禁用表单上的引导提交按钮
echo "<div class='panel panel-danger'><div class='panel-heading'>OBSERVACIONES</div><div class='panel-body'>";
echo "<div class='input-group'>";
echo "<label class='checkbox-inline'><input type='checkbox' name='visto' id='visto' value=''> Visto bueno del Responsable</label>";
echo "</div>";
echo "</div>";
...
echo "<input type='submit' class='btn btn-primary' value='SAVE' name='grabaperaus' formaction='update.php'>";
答案 0 :(得分:8)
对于复选框,您需要做的就是获取提交的Id
button
(在这种情况下为grabaperaus
),禁用onChange
checkbox
事件}}。
<input type="checkbox"
onchange="document.getElementById('grabaperaus').disabled = !this.checked;" name='visto'
id='visto'/>
答案 1 :(得分:1)
试试这个
$(document).ready(function(){
$('#save').prop('disabled', true);
$('#visto').click(function(){
if($(this).is(':checked'))
{
$('#save').prop('disabled', false);
}
else
{
$('#save').prop('disabled', true);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class='checkbox-inline'><input type='checkbox' name='visto'
id='visto' value=''> Visto bueno del Responsable</label>
<input type='submit' class='btn btn-primary' id="save" value='SAVE' name='grabaperaus' formaction='update.php'>
答案 2 :(得分:0)
使用Jquery
HTML:
<input type='checkbox' data-toggle='inputid'/>
<input id='inputid'/>
JAVASCRIPT:
function toggle(target) {
var toggle = $(target).data("toggle");
if (toggle) {
var obj = $("#" + toggle);
if (target.checked) {
obj.attr("disabled", "disabled");
} else {
obj.removeAttr("disabled");
}
}
}
$("input:checkbox").each(function(){toggle(this);}).on('input',function(){toggle(this);});