我在这里发帖再次,我似乎无法找到解决这个问题。我正在使用jquery和jstree插件来构建树,并基于jstree的node_id,我在div上显示了一些图像。我面临的问题是,有些图像无法加载,尽管它们在那里。当我遇到这个问题时,我通过检查图像的宽度验证了实际上没有加载的图像。以下是代码。我如何确保在显示图像之前加载图像。同样,任何帮助,不胜感激,因为我很新的jQuery的:jquery在div上显示图像
(document).ready(function() {
$("#div1").jstree({
"xml_data": {
"ajax": {
"url": "tree.xml"
},
"xsl": "nest"
},
"plugins": ["themes", "xml_data", "ui", "types"]
}).bind("select_node.jstree", function (event, data) {
var node_id = data.rslt.obj.attr("id");
if (node_id.indexOf("TEAM") >= 0) var teamA;
var teamB;
teamA = "image/" + node_id + "-scores.png";
teamB = "image/" + node_id + "-standing.png";
img1 = new Image;
img1.src = teamA;
img2 = new Image;
img2.src = teamB;
$("#div2").html(img1);
$("#div3").html(img2);
});
图像现在显示时,他们是100%加载? – 2012-07-23 17:16:12
@AndreasNilsson就像附加到DOM的任何其他图像一样。 ,我不确定你的问题是什么。 – 2012-07-23 17:25:05
.append不适用于我。每次,我点击一个节点,相同的将被追加到图像。 – 2012-07-23 17:27:32