Submit form using tag

前端 未结 11 2105
滥情空心
滥情空心 2020-12-12 23:55

I am trying to submit a form through onclick event on tag. I have tried triggering document.myform.submit(), this.form.submit(), parentNode.submit() etc. but none of this i

11条回答
  •  星月不相逢
    2020-12-13 00:46

    you can do it like this with raw javascript

    
        
            
    submit

    For those asking why I have a href element in my anchor tag, its because it's a compulsory part of an anchor tag, it may well work without but it's not to spec. So if you want to guarantee rendering etc you must give the engine a fully formed tag. So the above achieves this. You will see href="#" used sometimes but this is not always wanted as the browser will change the page position.

提交回复
热议问题