我有下面的代碼jQuery的全局變量不工作
$(document).ready(function() {
var $selection = $('<div class="image-selection" />')
.css({
opacity : 0.5,
position : 'absolute'
})
var $content = $('.content');
$('img', $content).click(function(){selectItem($(this))});
function selectItem(itemSelected){
$image = itemSelected;
$image.wrap($selection);
$selection.width(150).height(150);
}
})的問題;
我聲明$選擇作爲全局變量,但由於某種原因,當它在一個函數中的寬度或高度不會改變(選擇的大小改變): 如果我做了以下,它的工作原理:
var $selection = $('<div class="image-selection" />')
.css({
opacity : 0.5,
position : 'absolute'
})
var $content = $('.content');
$selection.width(150).height(150);
如果一些人理解所發生的事情,可以告訴我,我會非常感謝,我一直在試圖弄明白這一點,但我真的很掙扎。 非常感謝你
同意..或只是在包裝後鏈父母() – charlietfl 2012-02-28 00:16:10
是的,鏈接會很好。我只是想在原來的代碼中保留原始的一行,作爲參考。 – 2012-02-28 00:17:46
我試過之前,它的工作原理,我只是不明白爲什麼我不能使用$選擇,因爲包裝?... – MariaZ 2012-02-28 00:22:43