我試圖實現這裏找到的選擇選項。選擇選項JavaScript不起作用
當你按下按鈕,演示,你可以在網上看到選擇選項。不幸的是,當你點擊第二個選項似乎沒有被選中..默認值仍然存在..
不幸的是我花了太多時間試圖修改CSS文件,現在我卡在這裏!
你能弄清楚爲什麼選擇不正常?
這裏是我的代碼:http://jsfiddle.net/Y86Qj/
$(".dropdown dt a").click(function(){
if($(this).hasClass("open")) {
$(this).blur();
return false;
}
$(this).addClass("open");
$(this).closest(".dropdown").find("ul").animate({opacity: 'show', height: 'show'}, 'fast');
return false;
}).blur(function() {
$(this).removeClass("open");
$(this).closest(".dropdown").find("ul").animate({opacity: 'hide', height: 'hide'}, 'fast');
});
$(".dropdown dd ul a").click(function() {
var text = $(this).html();
$(this).closest("dt").find("a").html(text);
$(this).parents("ul").hide();
$(this).closest("select").val($(this).find("span.value").html());
return false;
});
/* Fancy Dropdowns */
function FancyDropdowns(selector){
$(selector).each(function() {
var source = $(this);
var selected = source.find("option[selected]");
var options = $("option", source);
var markup = '<dl class="dropdown">';
markup += '<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>';
markup += '<dd><ul>';
options.each(function() {
markup += '<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>';
});
markup += '</ul></dd>';
markup += '</dl>';
source.after(markup);
source.hide();
});
}
$(document).ready(function() {
FancyDropdowns(".dropdown.fancy");
$(".dropdown dt a").click(function(){
if($(this).hasClass("open")) {
$(this).blur();
return false;
}
$(this).addClass("open");
$(this).closest(".dropdown").find("ul").animate({opacity: 'show', height: 'show'}, 'fast');
return false;
}).blur(function() {
$(this).removeClass("open");
$(this).closest(".dropdown").find("ul").animate({opacity: 'hide', height: 'hide'}, 'fast');
});
$(".dropdown dd ul a").click(function() {
var text = $(this).html();
$(this).closest("dt").find("a").html(text);
$(this).parents("ul").hide();
$(this).closest("select").val($(this).find("span.value").html());
return false;
});
});
你必須張貼** **你的代碼,你的HTML和CSS,最好是在[的jsfiddle(http://jsfiddle.net/),所以我們可以看到你有什麼問題。此外,很確定這是一個JS問題,而不是一個CSS問題,所以你正在尋找錯誤的位置-_- – Ming
感謝您的答覆。代碼張貼在我提供的鏈接上。您也可以找到它這裏「view-source:http://captaincodemonkey.com/sites/default/files/fancydropdown.html」 – dionysosz
同樣,你得到否定票的原因是因爲你沒有發佈**你的**代碼,* *您的**嘗試解決問題,**您的**顯示努力解決**您的**問題。 – Ming