IE7 default form method is “GET”. How can I tell if it's user-entered or default?

后端 未结 3 1984
天命终不由人
天命终不由人 2020-12-11 04:41

If a user creates a form without a method attribute, it seems like most browsers will handle this at the time of form submission. So upon inspection of the form element afte

3条回答
  •  天命终不由人
    2020-12-11 04:57

    IE's behaviour is correct!(*) According to DTD:

    method      (GET|POST)     GET       -- HTTP method used to submit the form--
    

    or, in the XHTML DTD:

    method      (get|post)     "get"
    

    that means if the method attribute is omitted, not only does the form submit as GET by default, but the DOM actually should contain an Attr node for method with the DTD defaulted value GET.

    (*: well, sort of. IE is using the XHTML lower-case default in an HTML document where it should be the upper-case. Not that it really matters as the attribute is case-insensitive in HTML anyhow. And hey! It's IE getting the standard more-right than all the other browsers. It's a miracle!)

    So how do you tell that the Attr node was put there because of DTD attribute defaulting and not because it was in the source? With the DOM Level 1 Core specified flag:

    var form= document.getElementById('myform');
    var attr= form.getAttributeNode('method');
    var isomitted= attr===null || !attr.specified;
    

提交回复
热议问题