我有一個相當簡單的下拉式構建。這裏是活生生的例子:http://jsfiddle.net/K8VtB/jQuery:使用live()代替委託製作下拉()
我正在使用的代碼是這樣的:
$(document.body).delegate('.select .option', 'click' , function(e){
e.stopPropagation();
$(".select .option:not('.darr')").hide();
selectedOption = $(this).parents("div.select").find(".option:first");
$(this).siblings().show();
selectedOption.text($(this).text()).attr("title",this.title);
});
$(document.body).delegate('.select .option:not(".darr")', 'click' , function(e){
$(this).parents("div.select").find(".option:not('.darr')").hide();
console.log($(this).attr('data-ajax-link'));
});
$(document).click(function() {
$(".select .option:not('.darr')").hide();
});
我得到了一些幫助,這是因爲我以前從未使用過的委託。
我試着用live()方法做同樣的事情。我想知道爲什麼這只是不適合現場?或者我做錯了什麼?
這裏是我試圖做的同樣的劇本。沒什麼用。 http://jsfiddle.net/K8VtB/1/
任何人都可以幫我解決這個問題,並告訴我在使用live()時我做錯了什麼?
選擇的選項未定義'selectedOption =' – Rafay
是啊,那也沒有關係,這只是因爲我登錄一個不存在的屬性。只要看看就可以了。我只是想知道如何使下拉本身與live()而不是委託() – matt