包装/展开过程中的 jQuery 问题
考虑以下代码:
$(".lcontainer a").click(function () {
var current = $(this);
var name = current.attr('href');
document.getElementsByName('source')[0].value = name;
var fPicture = "css/imgs/Flash.png";
//If image is wrapped in link unwrap it
var newLink = $('<a/>').attr('href', name);
newLink.find('#prev').unwrap();
if (extension == "jpg" || extension == "png" || extension == "gif" || extension == "bmp") {
$(".mainCategory").html("Picture");
document.getElementById('prev').src = name;
}
else if (extension == "swf") {
$(".mainCategory").html("Game");
document.getElementById('prev').src = fPicture;
previewImage.wrap(newLink);
}
return false;
});
});
逻辑很简单:如果我们有 swf 文件,则放置 flash 符号,并用指向该文件的链接包装该符号。问题:单击另一个链接,符号未解开。
Consider the following code:
$(".lcontainer a").click(function () {
var current = $(this);
var name = current.attr('href');
document.getElementsByName('source')[0].value = name;
var fPicture = "css/imgs/Flash.png";
//If image is wrapped in link unwrap it
var newLink = $('<a/>').attr('href', name);
newLink.find('#prev').unwrap();
if (extension == "jpg" || extension == "png" || extension == "gif" || extension == "bmp") {
$(".mainCategory").html("Picture");
document.getElementById('prev').src = name;
}
else if (extension == "swf") {
$(".mainCategory").html("Game");
document.getElementById('prev').src = fPicture;
previewImage.wrap(newLink);
}
return false;
});
});
The logic is simple: if we have swf file put flash symbol and wrap the symbol with link pointing to this file. The problem: click another link and the symbol is not unwrapped.
您正在使用以下命令创建一个新的链接元素:
...因此:
...将找不到任何内容,因为
newLink
内部还没有任何内容。你确定你不想做这样的事吗?
You're creating a new link element with:
...so this:
... won't find anything because
newLink
doesn't have anything inside it yet.Are you certain you didn't want to do something like this?