Clearing my form inputs after submission

前端 未结 9 934
Happy的楠姐
Happy的楠姐 2020-11-30 04:25

I\'ve tried it a few different ways based on searches I\'ve done on the subject and for some reason I can\'t get it to work. I just want my text inputs and textarea to clear

9条回答
  •  遥遥无期
    2020-11-30 04:47

    The easiest way would be to set the value of the form element. If you're using jQuery (which I would highly recommend) you can do this easily with

    $('#element-id').val('')
    

    For all input elements in the form this may work (i've never tried it)

    $('#form-id').children('input').val('')
    

    Note that .children will only find input elements one level down. If you need to find grandchildren or such .find() should work.

    There may be a better way however this should work for you.

提交回复
热议问题