How can I submit a form using JavaScript?

后端 未结 10 1726
北海茫月
北海茫月 2020-11-22 16:43

I have a form with id theForm which has the following div with a submit button inside:

10条回答
  •  半阙折子戏
    2020-11-22 16:53

    You can use...

    document.getElementById('theForm').submit();
    

    ...but don't replace the innerHTML. You could hide the form and then insert a processing... span which will appear in its place.

    var form = document.getElementById('theForm');
    
    form.style.display = 'none';
    
    var processing = document.createElement('span');
    
    processing.appendChild(document.createTextNode('processing ...'));
    
    form.parentNode.insertBefore(processing, form);
    

提交回复
热议问题