2011-03-01 28 views
1

我想我的選擇框轉換成更時尚UL的下拉列表中,但選擇使用平變化,在它與轉換電平變化來選擇UL和jQuery

我想呼籲與document.search.submit()函數這對我的目的來說是一個很好的選擇,因爲我想我可以隱藏真正的選擇,下拉菜單也會改變這個值,然後提交表單,但這不起作用。我可以做些什麼來提交這些值到一個url參數。

注意在選擇的選項都在python動態生成

$(document).ready(function() { 
    createDropDown(); 

    $(".dropdown dt a").click(function(event) { 
    event.preventDefault(); 
    var dropID = $(this).closest("dl").attr("id"); 
    $("#" + dropID).find("ul").toggle(); 
    }); 

    $(document).bind('click', function(e) { 
    var $clicked = $(e.target); 
    if (! $clicked.parents().hasClass("dropdown")) 
     $(".dropdown dd ul").hide(); 
    }); 


    $(".dropdown dd ul a").click(function() { 
    var dl = $(this).closest("dl"); 
    var dropID = dl.attr("id"); 
    var text = $(this).html(); 
    var source = dl.prev(); 
    $("#" + dropID + " dt a").html(text); 
    $("#" + dropID + " dd ul").hide(); 
    source.val($(this).find("span.value").html()) 
    }); 
}); 

function createDropDown() { 
    var selects = $("select.dropdown_value"); 
    var idCounter = 1; 
    selects.each(function() { 
    var dropID = "dropdown_" + idCounter; 
    var source = $(this); 
    var selected = source.find("option[selected]"); 
    var options = $("option", source); 
    source.after('<dl id="' + dropID + '" class="dropdown"></dl>'); 
    $("#" + dropID).append('<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>'); 
    $("#" + dropID).append('<dd><ul></ul></dd>'); 
    options.each(function() { 
     $("#" + dropID + " dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>'); 
    }); 
    idCounter++; 
    }); 
} 
+0

太棒了!它立即工作。 – 2012-04-17 15:34:27

回答

0

固定它剛剛添加的document.search.submit()函數到點擊功能的底部,此代碼的任何優化的歡迎還是謝謝你