HTML with XML using jQuery
HTML with XML using jQuery
我有包含大量数据的XML文件。 现在我想选择一个有条件的价格。 我在 JavaScript 函数中设置了一个参数,但它没有给出期望的结果。 我认为这可以通过子节点完成,但我不知道这一点
XML 文件
<flights updated="2012-03-09T04:38:00.437" type="flights" ob_id="45792117" lastedit="2012-03-09T15:10:01" partner_id="63" activate_date="2012-02-15T00:00:00" page_id="9646" page_pk_id="12597" pos_pk_id="51565" pos="1" module_id="3" pos_name="Flights" product_type_id="4" product_type="flight" headline="Bali" destination="Bali" localised_destination="Denpasar" headline_no_html="Bali" price="199" deals_space_limited="0" deals_sold_out="0" qa_approved="1" tp_available="0" tp_weight="10" partner_eapid="0-25" partner_pid="25" publish_path="''dubvappdaily01'daily_aus'data'psf'" partner_lang_id="3081" FrTLAs="PER" ToTLAs="DPS" FrDate="2012-04-27T00:00:00" ToDate="2012-05-04T00:00:00" Airline="QZ"/>
<flights updated="2012-03-09T04:38:00.437" type="flights" ob_id="45792117" lastedit="2012-03-09T15:10:01" partner_id="63" activate_date="2012-02-15T00:00:00" page_id="9646" page_pk_id="12597" pos_pk_id="51565" pos="1" module_id="3" pos_name="Flights" product_type_id="4" product_type="flight" headline="Bali" destination="Bali" localised_destination="Denpasar" headline_no_html="Bali" price="199" deals_space_limited="0" deals_sold_out="0" qa_approved="1" tp_available="0" tp_weight="10" partner_eapid="0-25" partner_pid="25" publish_path="''dubvappdaily01'daily_aus'data'psf'" partner_lang_id="3081" FrTLAs="SYD" ToTLAs="DPS" FrDate="2012-04-27T00:00:00" ToDate="2012-05-04T00:00:00" Airline="QZ"/>
网页
<head>
<script type="text/javascript">
function myXml(origin, destination ) {
var x = xmlDoc.getElementsByTagName("flights");
for(i=0; i<x.length; i++) {
if (x[i].getAttribute('FrTLAs') == origin
&& x[i].getAttribute('destination') == destination) {
alert(x[i].getAttribute('price'))
}
}
}
</script>
</head>
<body>
<a href="#" onclick="myXml('SYD','Bali')">click me</a>
</body>
你错过了吗??
xmlDoc=loadXMLDoc("flights.xml");
中国香港中文首页
http://www.w3schools.com/dom/prop_element_attributes.asp
示例 2 非常清楚如何使用它
x=xmlDoc.getElementsByTagName("book")[0].attributes;
//here its would be getElementsByTagName("flights") in the loop
//then .attributes on it
// and then this
frtlas=x.getNamedItem("FrTLAs");
desti=x.getNamedItem("destination");
//and your code here
希望这有帮助
相关文章:
- jQuery Replacing, Using arrays
- Using jQuery with classes from ES6
- Javascript Object - using jQuery and this
- jquery using json object
- focus Using Jquery <tr> <td>
- Jquery Options using $(this)
- every 10 tr using 10n jquery
- filtet data by checkbox using jquery ajax mysql and php
- Jquery - Using promise API
- Focusin using live not working -jQuery
- Using Dashboard APIs or Frameworks using Javascript/JQuery
- Smooth requestAnimationFrame using Jquery.animate?
- jquery scale using animate
- jquery FullCalendar using MVC and JSON
- jQuery - using .prepend()
- jQuery using index()
- Jquery - Using a function with .click and 'this'
- Laravel 5 jQuery Using AJAX
- jQuery using event.preventDefault() with on('input')
- jQuery Using .on() with .each()