jquery .append() case sensitive element

前端 未结 4 676
北恋
北恋 2020-12-19 14:39

Hi I need to create xml from data in form to send it to webservice. The problem is that .append() is case insensitive, so .append(\'\')

4条回答
  •  囚心锁ツ
    2020-12-19 14:53

    jQuery.parseXML will always create a new DOMParse and a new Document, so it is pretty heavy.

    A better approach would be to use the (unintuitive) parseHTML, using the context paramter:

    // Create the context XML document; doc and $doc is reusable
    var doc = (new DOMParser()).parseFromString( '', 'text/xml' ); 
    var $doc = $( doc.documentElement )
    
    // Create case-sensitive XML element;
    // this will call doc.createElement( 'EDO' ), as of jQuery 2.1.3
    $doc.append( $.parseHTML( '', doc ) ); 
    

提交回复
热议问题