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

后端 未结 3 1980
天命终不由人
天命终不由人 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 05:03

    (How do I reply to a specific reply?) (in reply to bobice:)

    IE's behaviour is correct!

    If I read the relevant specs correctly, these are all the case in conformant implementations (which IE is not):

    form.method == "get" /* IETF and W3C HTMLs and XHTMLs */ || form.method == "GET" /* HTML5* */
    form.hasAttribute ("method") == false
    form.getAttribute ("method") == ""
    form.getAttributeNode ("method") == null
    

    In Chrome "8.0.552.28 beta" on Linux, I get (also not correct)

    var form = document.createElement ("form")
    undefined
    form.method == "get" || form.method == "GET"
    false /* actual value is "" */
    form.hasAttribute ("method") == false
    true
    form.getAttribute ("method") == ""
    false /* actual value is null */
    form.getAttributeNode ("method") == null
    true
    
    • In HTML5, method is an enumerated attribute equal to one of GET, POST, PUT, DELETE. form.method must "reflect" the method attribute, which in the case of an enumerated attribute means the specified value if it matches one of the valid values or else the first valid value. (I may be reading this slightly wrong, but that is my interpretation.)

提交回复
热议问题