如何通过另一个元素

时间:2017-05-05 07:24:57

标签: javascript jquery xml

<dataset>
<study recNO="0" seriesRecCount="1">
      <patientID>123456</patientID>
      <accessionNumber>M120170428105320</accessionNumber>
      <patientIDID>35</patientIDID>
      <studyUID>2.25.143966910120672170538921915162328371094</studyUID>
      <studyUIDID>251</studyUIDID>
</study>
<study recNO="1" seriesRecCount="1">
      <patientID>123456</patientID>
      <accessionNumber>M120170428105233</accessionNumber>
      <patientIDID>35</patientIDID>
      <studyUID>2.25.303229748643803883750255516818503774905</studyUID>
      <studyUIDID>252</studyUIDID>
</study>
</dataset>

我从url查询字符串中获取 accessionNumber 。 我想通过 accessionNumber 获得 studyUID 我怎么能用jQuery做什么?

非常感谢

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

var xml = $('<dataset><study recNO="0" seriesRecCount="1"><patientID>123456</patientID><accessionNumber>M120170428105320</accessionNumber><patientIDID>35</patientIDID>studyUID>2.25.143966910120672170538921915162328371094</studyUID><studyUIDID>251</studyUIDID></study><study recNO="1" seriesRecCount="1">      <patientID>123456</patientID><accessionNumber>M120170428105233</accessionNumber><patientIDID>35</patientIDID><studyUID>2.25.303229748643803883750255516818503774905</studyUID>      <studyUIDID>252</studyUIDID></study></dataset>');

function getStudyUIDByAccessionNumber (access) {
    for (var study of a.find('study')) {
        var accessionNumber = study.getElementsByTagName('accessionNumber')[0].innerHTML;
        if ( accessionNumber == access) {
            return (study.getElementsByTagName('studyUID')[0].innerHTML);
        }
    }}

getStudyUIDByAccessionNumber('M120170428105233');