我试图提醒$ xml.html()的值,但我得到了未定义。有我的代码
var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
$xml.find('TaxPayer').text('shri');
alert($xml.html());
答案 0 :(得分:2)
<强> JS FIDDLE DEMO 强>
<强> JS FIDDLE DEMO 2 强>
var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
alert($xml.find('xml').html());
alert($xml.find('xml').text());
var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
alert($xml.find('xml').html());
alert($xml.find('xml').text());
$xml.find('FirstName').text('satinder');
alert($xml.find('xml').html());
alert($xml.find('xml').text());
答案 1 :(得分:0)
试试这个
var xml =$('<XMLDocument />')
xml.append($('<TaxPayer/>')
.append($('<PersonalInformation/>')
.append($('<FirstName/>').text('aashu'))));
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml.html());
xml.find('TaxPayer').find('FirstName').text('shri');
alert(xml.html());
这可能会有所帮助。 live demo