html5 required attribute on non supported browsers

前端 未结 5 1600
失恋的感觉
失恋的感觉 2020-12-06 19:43

I have a web application which makes use of the HTML5 required attribute frequently. However Safari and ie 8/9 do not support this attribute. Is there a jQuery

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 20:09

    You could shim it simply...

    if ($("").prop("required") === undefined) {
        $(document).on("submit", function(event) {
             $(this)
               .find("input, select, textarea")
               .filter("[required]")
               .filter(function() { return this.value; })
               .each(function() {
                   // Handle them.
               });
        });
    }
    

提交回复
热议问题