display data in a textbox when checkbox is checked

前端 未结 2 1188
谎友^
谎友^ 2020-12-21 15:31

I have three text boxes having id text1, text2, text3 and one checkbox having id check. I am displaying something in first textbox let\'s say 10. Now if i will check checkbo

2条回答
  •  爱一瞬间的悲伤
    2020-12-21 16:08

     $('#check').change(function(){if($(this).is(':checked'))$('#text2').val(20);});
    

    If you want to clear the value when it is unchecked use:

     $('#check').change(function(){if($(this).is(':checked'))$('#text2').val(20);else $('#text2').val(''); });
    

提交回复
热议问题