我需要单击列表项以使用xml文件中的节点中的文本替换div中的文本.
我单击列表项并将结果存储在变量中.然后我加载xml,找到我需要的节点的标题,并创建结果的变量.然后我运行if语句,如果两个变量相等,则将xml放入div中.
我第一次点击列表项,这是有效的.列表中的正确项与xml中的正确节点匹配,正确的文本放在div中.
但是,当我单击其他列表项时,文本不会被替换.警报显示第二次单击获得了正确的信息,但最终,div内容未被替换.
代码在这里:
- New York
- Disconnexion
- Jack at Sea
$(document).ready(function(){
$("#gallery_id li").on('click', function(e) {
var htmlTitle = (this.id);
$.ajax({
type: "GET",
url: "/mwebphoto/xml/albums.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('photoAlbum').each(function(){
var xmlAlbum= $(this);
var xmlTitle = $(this).find('title').text();
var xmlEmbedCode = $(this).find('embedCode').text();
alert ('this is html titled ' + htmlTitle);
alert ('this is xml titled ' + xmlTitle);
if(xmlTitle=htmlTitle)
alert ('this is matched xml title' + xmlTitle);
$("#slideshow").replaceWith(xmlTitle);
});
}
});
});
});
感谢帮助.我不轻易问.我花了很多时间研究它并以我能想到的方式进行研究.我错过了一些非常简单的东西,但却找不到它.