2016-06-23 91 views
1

我需要啓用或禁用引導提交按鈕在窗體上,如果一個複選框cheched或不如何禁用或啓用引導提交按鈕,如果選中的複選框

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'>"; 

回答

2

對於複選框,所有你需要做的是得到您的提交buttongrabaperaus在這種情況下)禁用它onChange事件的checkbox

<input type="checkbox" 
onchange="document.getElementById('grabaperaus').disabled = !this.checked;" name='visto' 
id='visto'/> 
0

試試這個

\t 
 
$(document).ready(function(){ 
 
\t $('#save').prop('disabled',true); 
 
$('#visto').click(function(){ 
 
\t 
 
\t if($(this).is(':checked')) 
 
\t { 
 
\t \t $('#save').prop('disabled',false); 
 
\t \t 
 
\t } 
 
\t else 
 
\t { 
 
\t \t $('#save').prop('disabled',true); 
 
\t } 
 
}); 
 

 
});
<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'>

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);}); 
相關問題