我是jQuery的新手,所以如果我走錯了方向,請指教我。來自jQuery選擇器的jQuery對象
我有一個功能,把參數作爲一個「jQuery對象」,像這樣:
function protectImageFromRightClick(image_object) {
// yeah ok i know this is only a dumb protection!!
image_object.bind('contextmenu', function(e) {
return false;
});
image_object.mousedown(function(){
return false; // for prevent drag
});
}
,我想打電話給它選擇。我試着each()
稱呼它:
$(".photo").each(function (i) {
protect(this);
});
但this
似乎是指不具有任何.bind()
方法..我不很明白我怎麼能解決這個DOM對象..有任何想法嗎?
面對的是,我使用的功能可按其他地方的代碼,以便像一個解決方案:
$('some selection').bind()
是不是一個很好的解決方案,因爲這樣我會只寫代碼的重複..
然而,JavaScript是不打算採取這樣的功能,例如從右鍵單擊保護。請注意,用戶可以輕鬆關閉JavaScript。 – cIph3r 2013-02-17 23:57:58
是的,我知道它:) – nkint 2013-02-18 00:11:19