I've searched for the answer to this problem but still can't get this to work:
<script type="text/javascript">
$(document).ready(function (){
validate();
$('#contact_subject').change(validate);
});
function validate(){
if ($('#contact_subject').val().length > 0 {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
</script>
I want to make sure #contact_subject
has data or else disable the button.
I've searched for the answer to this problem but still can't get this to work:
<script type="text/javascript">
$(document).ready(function (){
validate();
$('#contact_subject').change(validate);
});
function validate(){
if ($('#contact_subject').val().length > 0 {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
</script>
I want to make sure #contact_subject
has data or else disable the button.
2 Answers
Reset to default 5I think you are missing a bracket ) in if condition
function validate(){
if ($('#contact_subject').val().length > 0) {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
Change the event.Try this: http://jsfiddle/e0t7qv56/1/
$("#field").keyup(function(){
console.log($(this).val().length);
if($(this).val().length)
$("#btn").prop('disabled', false);
else
$("#btn").prop('disabled', true);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745456232a4628497.html
评论列表(0条)