html5 required and jQuery submit()

后端 未结 9 596
我在风中等你
我在风中等你 2020-12-09 07:56

I\'m trying to implement html5 into a form, but I came with a problem when I submit the form through jquery and try to use the html5 \"required\" attribute.

Here is

9条回答
  •  粉色の甜心
    2020-12-09 08:52

    I had exactly the same problem. I had a single button that I had deliberately set NOT to be a submit because it was on first click revealing a form. On a second click of the same button $('form[name=xxx]').submit(); was firing and I found as well that the HTML5 validation doesn't work.

    My trick was to add a line of code so that after my first click of this button occurs I change its type to submit dynamically.

    $("#btn").attr("type","submit");
    

    Which worked like a charm!

提交回复
热议问题