我知道我的选择器值和我的 xml 变量没有连接,但我不太清楚如何连接它们。我知道 xml 正在通过,但我需要将其链接到选择值后显示的内容。这是我所拥有的:
新代码
<script src="js/xmlDom.js"></script>
<script type="text/javascript">
var cityID;
var city;
var amt;
$(document).ready(function() {
$.ajax({
type: "GET",
url: "data/precipData.xml",
dataType: "xml",
success: makeItRain
});
});
function makeItRain(xml) {
console.log($.xmlDOM(xml));
$.xmlDOM(xml).find("Row").each(function () {
cityID = $(this).attr("id");
city = $(this).find("city").text();
amt = $(this).find("amt").text();
$('<option>' + city + '</option>').appendTo('.selectCity');
console.log('appending');
$(".selectCity").change(function () {
$('select option:selected', this).append(cityID);
$(".name").append(city);
console.log('city');
$(".ammount").append(amt);
console.log('amt');
});
//.change();
});
};
</script>
</head>
<body>
<select class="selectCity">
<option id="default">Select a city</option>
</select>
<div class="name">
</div>
<div class="ammount">
</div>
</body>
旧代码
<script type="text/javascript">
var cityID;
var city;
var amt;
$(document).ready(function() {
$.ajax({
type: "GET",
url: "data/precipData.xml",
dataType: "xml",
success: makeItRain
});
});
function makeItRain(xml) {
$(xml).find("Row").each(function(){
cityID = $(this).attr("id");
city = $(this).find("city").text();
amt = $(this).find("amt").text();
$('<option>' + city + '</option>').appendTo('.selectCity');
console.log('appending');
$(".selectCity").change(function() {
$('select option:selected', this).append(cityID);
$(".name").append(city);
console.log('city');
$(".ammount").append(amt);
console.log('amt');
});
//.change();
});
};
</script>
</head>
<body>
<select class="selectCity">
<option id="default">Select a city</option>
</select>
<div class="name">
</div>
<div class="ammount">
</div>